Google跟踪代码管理器和单页应用 [英] Google Tag Manager and Single Page apps
问题描述
我正在尝试将Google跟踪代码管理器与我的Ember应用集成.我很难理解如何通知GTM页面已更改,并发送页面查看事件.
I'm trying to integrate Google Tag Manager with my Ember app. I'm having a hard time understanding how to notify GTM that the page changed, and send a page view event.
我在网上阅读了很多东西,大部分都是围绕为虚拟页面"或其他内容创建新变量而工作的,但是显然这并不理想.
I've read a lot of things online, mostly working around creating a new variable for a "virtual page" or something, but obviously this is far from ideal.
我希望能够仅使用dataLayer.push
通知页面实际已更改.有没有我找不到的简便方法,还是在SPA上使用GTM进行跟踪真的很痛苦吗?
I'd like to be able to just use dataLayer.push
to notify the page actually changed. Is there an easy way out I didn't find or is it really a pain to track with GTM on SPA?
推荐答案
这是很久以前问过的.使用GTM的当前功能集,您可以轻松设置SPA页面跟踪,而不会带来很多麻烦.
This was asked quite a while ago. With the current feature set of GTM, you can easily set up SPA page tracking without much trouble.
首先,转到Triggers
并创建一个新触发器.选择History Change
作为触发类型.这将创建一个触发器,每次位置历史记录更改时都会触发.
First, go to Triggers
and create a new trigger. Select History Change
as the trigger type. This will create a trigger that fires every time the location history changes.
然后创建一个新的Tag
类型的Tag
,并按照下面的屏幕截图进行设置.
Then create a new Tag
of Universal Analytics
type and set it up as per the screenshot below.
[
对于触发器,设置先前定义的历史记录更改"触发器,即可完成.每次在SPA中进行导航时,都会触发具有正确页面路径的页面查看事件.
As for the trigger, set the previously defined History Change trigger, and you're done. Every time a navigation occurs in your SPA, a page view event with the proper page path will be triggered.
正如trognaders
在评论中指出的那样,这不会跟踪初始页面视图.为了解决这个问题,只需为您的代码添加一个额外的触发器即可在页面查看"事件(所有页面")上触发.请参见下面的屏幕截图.
as trognaders
pointed out in a comment, this does not track the initial page view. To remedy, simply add an additional trigger for your tag that fires on the Page View event (All Pages). See screenshot below.
这篇关于Google跟踪代码管理器和单页应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!