GTM randomly skips initial pageview in single page app

后端 未结 3 1501
一向
一向 2021-01-07 20:20

I have Pageview tag in Google Tag Manager that tracks SPA pageviews, identical to the one described in this guide. Basically it is Universal Analytics

3条回答
  •  轮回少年
    2021-01-07 20:28

    As @kemsky suggested, GTM lifecycle is tied to internal gtm.load event, which happens on window onload. So DOMContentLoaded may be too early to bootstrap.

    Considering that GTM script was loaded prior to SPA script,

    window.addEventListener('load', () => {
      platformBrowserDynamic().bootstrapModule(MyAppModule);
    });
    

    callback will be triggered when GTM is ready to receive history change events, and there should be no race conditions.

提交回复
热议问题