如何在JS中手动将gclid参数传递给Google Analytics(分析) [英] How to pass gclid parameter manually in JS to Google Analytics

查看:79
本文介绍了如何在JS中手动将gclid参数传递给Google Analytics(分析)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站构建,其中包含世界上最惊人的框架之一.不幸的是,它有一个缺点.它不允许使用查询参数,例如:www.url.com/page/1可以,但是www.url.com/?page=1不能.当您放置此URL时,它将使用浏览器历史记录,因此URL中没有查询参数.

I have a website build with one of the most amazing frameworks on the world. Unfortunately it has one downside. It does not allow to use query parameters, for example: www.url.com/page/1 is ok but www.url.com/?page=1 is not ok. When you put this URL it uses browser history so there is no query parameters left in URL.

我在Google Adwords中有一个广告系列,可以将用户定向到该网站.自动标记功能已开启.我注意到我的网站获得了1万次点击,但是Google Analytics(分析)并未报告Adwords来源的此类数字.

I have a campaign in Google Adwords that directs users to this website. Auto tagging is on. I've noticed there are 10k clicks to my website, but Analytics does not report such number for Adwords source.

我发现Adwords自动标记将gclid参数添加到目标网址.然后,Google Analytics(分析)了解有关该广告系列的所有信息,因为Analytics(分析)和Adwords链接在一起,我应该获得有关广告系列及其转化的漂亮分析数据.

I discovered that Adwords auto tagging is adding gclid parameter to the destination URL. Than, Analytics knows everything about the campaign because Analytics and Adwords are linked together and i should have pretty analytics data on campaigns and their conversions.

但是我没有.由于我最好的网站框架之一使用其JS代码删除了gclid参数,因此Analytics(分析)不会注意到gclid,也不会保存用户来源.

But i don't have it. Since my one of greatest website frameworks removes with its JS code the gclid parameter, Analytics does not notice the gclid and not save the source of the user.

要检查这是否真的是我的网站框架问题,我已在我的网站中添加了utm(umt)参数,并在Analytics(分析)中实时检查了源代码.据报道,它不是我在参数中提供的来源,而是直接访问.

To check if it is really my great website framework issue, i've added utm(umt) parameters to my website and checked source in real time in Analytics. It was not reported as source i provided in parameters but a direct visit.

我希望能够分析Google Analytics(分析)中Adwords的效果.不幸的是,我无法更改我的框架,因为它是世界上最强大的框架之一.但是我已经注意到,在解雇该框架的JS代码之前,我有一会儿带有参数gclid的URL.

I would like to be able to analize Adwords performance in Analytics. I can not change unfortunately my framework because it is one of the greatest on the world. But i have noticed that before JS code of the framework is fired i have for a while a URL with the parameter gclid.

下面的一些行中有我的Google Analytics(分析)跟踪代码.显然,它试图从URL中获取gclid.但这对他来说为时已晚.当Google Analytics(分析)尝试读取时,gclid参数消失了.

Some lines below i have my Google Analytics tracking code. Obviously it tries to get gclid from the URL. But it is too late for him. The gclid parameter is gone when Google Analytics tries to read it.

所以我的问题是:由于我有gclid,是否有Google Analytics(分析)将其传递给他的任何方法?像这样说:

So my question is: since i have gclid, is there any method of Google Analytics to pass it to him? Like say:

var gclid = getGClidBeforeItsToLate();//我已经遮住了

var gclid = getGClidBeforeItsToLate(); // i have it covered

//很棒的框架内容

HeyGoogleAnalyticsHereYouGoItsYourGclidTakeCare(gclid);

HeyGoogleAnalyticsHereYouGoItsYourGclidTakeCare(gclid);

?

推荐答案

覆盖"位置"字段,并附加gclid参数.

Override the "location" field and append the gclid parameter.

if(gclid) {
  ga('set', 'location', document.location + '?gclid=' + gclid);
}
ga('send','pageview')

您必须使用位置字段,而不要使用页面"字段(它占用页面路径),因为即使您在路径中添加参数,后者也不会更改归因.

You have to use the location field, not the "page" field (which takes the page path), since the latter does not change attribution even if you add parameters t the path.

如果您手动设置了广告系列参数("utm参数"),则可以通过campaignMedium/campaignSource/campaignName字段进行设置,但是由于无法从gclid获取单个广告系列值,因此您必须覆盖该位置(GA会从浏览器的地址栏中清除它收集到的内容,并使用您传入的值.

If you have manually set campaign parameters ("utm parameters") you could set them via the campaignMedium/campaignSource/campaignName fields, but since you cannot get the individual campaign values from the gclid you have to overwrite the location (at which point GA will dismiss what it has gathered from the address bar of the browser and use the value you passed in).

这篇关于如何在JS中手动将gclid参数传递给Google Analytics(分析)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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