3

Has anyone figured out a way to get a Google Tag Manager container to fire all its tags under Turbolinks?

I'm running a rails 4.0 application (with Turbolinks) and have put the code below in a footer that I render in every page (inside the tags):

<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-XXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<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=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXX');</script> 
<!-- End Google Tag Manager -->

(where XXXXX is my GTM container ID)

Unfortunately it does not fire a single tag when I'm browsing between pages (I assume because of Turbolinks). However, everything works fine if I refresh the page I'm in.

I've seen people posting questions about workarounds for Google Analytics tags that seemed to tackle that issue, but never for a full GTM container. Help? Anybody?

1

1 Answer 1

0

You have to cause virtual page views to fire when using GTM with Turbolinks: Googletagmanager with Turbolinks

Also, you want to load the GTM script immediately after the <body> open tag.

3
  • 1
    Do you mind checking this meta question: meta.stackoverflow.com/questions/277006/… we are wondering how you got that link.....
    – rene
    Nov 17, 2014 at 17:53
  • Iirc, I searched Google and copied the url from my browser after visiting the page. Or I could have followed a link on SO to the page and then copied the the url. Nov 17, 2014 at 18:19
  • It's been almost 10 years... has anything changed? And the link is broken
    – hook38
    Jan 13, 2023 at 5:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.