Google Tag Manager - override page-tracking.es6.js

AI-generated summary

Google Tag Manager - Override page-tracking.es6.js

mathieu is seeking help in understanding and overriding the page-tracking.es6.js file in Google Tag Manager. Upon loading the first page, two events are sent: a “Page View” event and a “VirtualPageView” event, while only a “VirtualPageView” event is sent on subsequent page changes. Mathieu attempted to override the file by creating a plugin in the assets/javascripts/initializers/ folder but was unsuccessful.

neil responded that overriding the file is not as simple as renaming it and suggested that any changes to the GTM tracking must not break the universal analytics integration with GTM. Neil welcomes improvements to the GTM tracking from those with a deeper understanding of GTM.

Hello there :slight_smile:

I’m working with Google Tag Manager and there is something I don’t understand on your implementation:

When I load the first page, I have two events sent:

  • a « Page View » event;
  • a « VirtualPageView » event.
    Then, on all page changes:
  • a « VirtualPageView » event.
    Why are you sending two events on the first page load?

I tried to override your page-tracking.es6.js in the initializers folder by creating a plugin which includes the same file in assets/javascripts/initializers/ but this doesn’t work and your file is executed, not mine. Maybe I’m not doing things good to override one of initializers file. What should I do?

I don’t know what can I do to do that so if someone can help me… thanks :slight_smile:

Mathieu.

Have we tried this @neil?

I haven’t tried overriding page-tracking.js. I don’t think it’s as simple as putting your own file with the same name in a plugin.

Regarding the GTM tracking, I welcome any improvements from anyone who understands GTM better than me. Keep in mind that any changes must not break the universal analytics integration with GTM. I seem to remember the way it is now was to make sure analytics works via GTM.