Firing tags in GTM (Google Tag Manager) containers under turbolinks

感情迁移 提交于 2019-12-13 16:50:24

问题


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:


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.



来源:https://stackoverflow.com/questions/26948288/firing-tags-in-gtm-google-tag-manager-containers-under-turbolinks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!