在turbolinks下在GTM(Google跟踪代码管理器)容器中触发代码 [英] Firing tags in GTM (Google Tag Manager) containers under turbolinks

查看:119
本文介绍了在turbolinks下在GTM(Google跟踪代码管理器)容器中触发代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能找到一种方法来获取Google跟踪代码管理器容器以在Turbolinks下触发其所有代码吗?

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

我正在运行Rails 4.0应用程序(带有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 -->

(其中XXXXX是我的GTM容器ID)

(where XXXXX is my GTM container ID)

不幸的是,当我在页面之间浏览时,它不会触发单个标签(我想是因为Turbolinks).但是,如果刷新页面,一切都会正常.

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.

我见过有人发布关于Google Analytics(分析)标签变通办法的问题,这些变通办法似乎可以解决该问题,但从来没有提出过完整的GTM容器.帮助?有人吗?

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?

推荐答案

在将GTM与Turbolink一起使用时,您必须引起虚拟页面视图的触发:

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

此外,您还想在<body>打开标记之后立即加载GTM脚本.

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

这篇关于在turbolinks下在GTM(Google跟踪代码管理器)容器中触发代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆