Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
410 views
in Technique[技术] by (71.8m points)

reactjs - Is is possible to trigger 'Container Loaded' twice or force GTM to reload ? (React)

I am actually working on a large web application, which was initially built with Symfony/Twig, and that is gradually refactored using React. But since I am using React, some of my pages get no "views" in Google Tag Manager (GTM).

I followed this guide to use GTM in React. But I have a lot (tens) of Tags and Triggers in GTM, based on the 3 native events "Container loaded" (gtm.js), "DOM Ready" (gtm.dom) and "Window Loaded" (gtm.load).

The first solution (from the guide) is to add a new custom trigger (based on History Source) and link our tags on this new trigger. But since I have too many tags, this is not a satisfying solution.

The second solution is to manually trigger events, using the datalayer. This works fine, I can easily trigger the "DOM Ready" and "Window Loaded" events. But it does not work as expected for "Container Loaded". I guess that GTM does not handle this event more than once per page load.

So, here are my questions:

  • Is it possible to "fake a reload" in GTM (so that GTM act like if I opened a new page)?
  • Or is it possible to trigger "Container Loaded" (gtm.js) multiple times?

Screenshot of a "normal" Container Loaded trigger:

screenshot gtm

Screenshot of a manually called Container Loaded trigger (from React):

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

No. You can call gtm.dom or gtm.load more than once but not gtm.js.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...