3

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

Dony
  • 1,543
  • 2
  • 10
  • 25

2 Answers2

0

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

Michele Pisani
  • 13,567
  • 3
  • 25
  • 42
0

You can empty the dataLayer if you switch from page to page in your SPA. Which should simulate something like a fake reload. Also, it's best practice to use VirtualPageViews to track your website.

Raoul Dundas
  • 406
  • 4
  • 11