diff --git a/layout/includes/head/analytics.pug b/layout/includes/head/analytics.pug index 7412c41..ce54837 100644 --- a/layout/includes/head/analytics.pug +++ b/layout/includes/head/analytics.pug @@ -35,8 +35,14 @@ if theme.microsoft_clarity if (theme.google_tag_manager && theme.google_tag_manager.tag_id) script. - (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': - new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], - j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= - "!{theme.google_tag_manager.domain ? theme.google_tag_manager.domain : 'https://www.googletagmanager.com'}/gtm.js?id="+i+dl;f.parentNode.insertBefore(j,f); - })(window,document,'script','dataLayer','!{theme.google_tag_manager.tag_id}'); + window.initGTM = function() { + (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': + new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], + j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= + "!{theme.google_tag_manager.domain ? theme.google_tag_manager.domain : 'https://www.googletagmanager.com'}/gtm.js?id="+i+dl;f.parentNode.insertBefore(j,f); + })(window,document,'script','dataLayer','!{theme.google_tag_manager.tag_id}'); + }; + window.initGTM(); + btf.addGlobalFn('pjaxComplete', () => { + window.initGTM(); + }, 'google_tag_manager'); \ No newline at end of file