简体   繁体   English

如何从Google跟踪代码管理器调用_trackPageView获取AJAX页面?

[英]How to call _trackPageView from Google Tag Manager for an AJAX page?

I have a page loaded in via AJAX. 我有一个通过AJAX加载的页面。

In Google Analytics I could have just called gaq.push('_trackPageView','/someurl') in my AJAX success function. 在Google Analytics(分析)中,我可以在AJAX成功函数中调用gaq.push('_trackPageView','/someurl') However I can't seem to find a way to do this when implementing GA via Google Tag Manager. 但是,当通过Google跟踪代码管理器实施GA时,我似乎找不到解决方法。

The only alternative seems to be a "virtual page view" event , which isn't exactly what I'm after: Does anyone know how to do this? 唯一的选择似乎是“虚拟页面浏览”事件 ,它与我所追求的不完全相同:有人知道如何执行此操作吗?

on the Ajax success, do: 关于Ajax的成功,请:

dataLayer.push({
'event':'sendVirtualPageview',
'vpv':'/blah/blah'
});

The 'event' is just to send the virtual pageview to GTM. “事件”只是将虚拟综合浏览量发送到GTM。 It's not a traditional, although it could be, Google Analytics event. 尽管可能是Google Analytics(分析)活动,但这不是传统活动。

You should be able to folllow the rest of the tutorial to create your rule and setup the tag type. 您应该能够按照本教程的其余部分来创建规则并设置标签类型。

Here's how you enable Virtual Page Views on your Google Analytics tag in GTM. 以下是在GTM中的Google Analytics(分析)标签上启用虚拟页面浏览量的方法。

GTM v2: GTM v2:

Go to the Variables page. 转到“变量”页面。 Enable the Event variable {{event}} by ticking the Event checkbox inside Utilities under the Enable Built-in Variables heading. 通过选中“启用内置变量”标题下的实用程序内的Event复选框,启用事件变量{{event}}

Create a variable named Virtual Url with type Data Layer Variable and set the Data Layer Variable Name to "virtualUrl" . 创建一个名为Virtual Url的变量,其类型为Data Layer Variable ,并将Data Layer Variable Name设置为"virtualUrl"

Go to the Triggers page. 转到“触发器”页面。 Create a trigger named Virtual Page View with type Custom Event and set the Event name to "virtualPageView" . 创建一个名为Virtual Page View的触发器,其类型为Custom Event ,并将Event名称设置为"virtualPageView"

Create a tag GA Virtual Page Views with product Google Analytics Universal. 使用产品Google Analytics Universal创建标记GA Virtual Page Views Set your Tracking ID UA-xxxxxx-xx . 设置您的跟踪ID UA-xxxxxx-xx Set the track type to Pageview . 将曲目类型设置为Pageview

Under More Settings > Fields to set, click + Add Field . 在更多设置>要设置的字段下,单击+ Add Field Set Field Name to page with value {{Virtual Url}} . 设置字段名称到page与价值{{Virtual Url}}

You can add additional fields here, such as title, UTM campaign etc. Add variables then add them here. 您可以在此处添加其他字段,例如标题,UTM广告系列等。添加变量,然后在此处添加它们。

Click Continue. 单击继续。 Under Fire On, click More . 在开火下,单击More In the triggers popup, tick Virtual Page View . 在触发器弹出窗口中,勾选Virtual Page View Click Save. 单击保存。

Click Create Tag. 单击创建标记。

GTM v1: GTM v1:

Create a macro {{Virtual Url]} referring to dataLayer variable "virtualUrl" . 创建一个宏{{Virtual Url]}引用dataLayer变量"virtualUrl"

Create a {{Virtual Page View}} rule as {{event}} equals "virtualPageView" . 创建一个{{Virtual Page View}} {{event}} equals "virtualPageView"{{Virtual Page View}}规则。

You should already have an {{event}} macro, but if you don't, create one using the dataLayer variable "event" . 您应该已经有了一个{{event}}宏,但如果没有,请使用dataLayer变量"event"创建一个宏。

Updates to your Google Analytics tag: 您的Google Analytics(分析)标签的更新:

  • More Settings > Basic Config, tick "Virtual Page Path" and use macro {{Virtual URL}} . 更多设置>基本配置,勾选"Virtual Page Path"并使用宏{{Virtual URL}}
  • Remove the {{All Pages}} firing rule. 删除{{All Pages}}触发规则。
  • Add the {{Virtual Page View}} firing rule. 添加{{Virtual Page View}}解雇规则。

GA Fields: GA栏位:

page = the path portion of a URI. page = URI的路径部分。 eg. 例如。 /blog/topic/post.html /blog/topic/post.html

title = used to specify the <title> contents title =用于指定<title>内容

campaignMedium = used to specify the URI utm_medium campaignMedium =用于指定URI utm_medium

campaignSource = used to specify the URI utm_source campaignSource =用于指定URI utm_source

campaignTerm = used to specify the URI utm_term campaignTerm =用于指定URI utm_term

campaignContent = used to specify the URI utm_content campaignContent =用于指定URI utm_content

campaignName = used to specify the URI utm_campaign campaignName =用于指定URI utm_campaign

Usage: 用法:

In your web app, call it like so: 在您的网络应用中,将其称为:

dataLayer.push({
    'event': 'virtualPageView',
    'virtualUrl': '/relative/page/path',
    'virtualTitle': 'My page title'
});

You can rename any of the variables above - this is just an example based on how we do it. 您可以重命名上面的任何变量 - 这只是一个基于我们如何做的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM