我正在尝试根据Cookie过滤公司网站的Google Analytics数据。我不想跟踪内部流量,但我不能只根据IP地址范围进行过滤,因为我们还想跟踪一些内部用户。我有一些非常简单的代码来添加cookie,但我不知道在哪里添加代码。我对cookie很陌生,在网上找不到任何关于如何实际添加或使用cookie的明确内容。
<html>
<head>
<title>Remove My Internal Traffic from Google Analytics</title>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-YY']);
_gaq.push(['_setVar','employee']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
所以我的问题是,这段代码到底在哪里?感谢您使用cookies帮助我的新手技能。
答案 0 :(得分:3)
不要使用setVar(不推荐使用),请使用_setCustomVar:
_setCustomVar(index, name, value, opt_scope)
呼叫在_trackPageview呼叫之前进行。
标准GA中有五个自定义变量(溢价50),即“索引”。 “名称”和“价值”应该清楚。
CustomVars对当前页面,会话或访问者有效(在最后一种情况下,它们有效,直到访问者在浏览器中清除cookie,除非他在再次访问您的网站之前等待六个月)。 / p>
就像每个带有异步GA代码的指令一样,它被“推”到gaq-Array上,所以正确的调用将是:
_gaq.push(['_setCustomVar',
1, // This custom var is set to slot #1. Required parameter.
'Items Removed', // The name acts as a kind of category for the user activity. Required parameter.
'Yes', // This value of the custom variable. Required parameter.
2 // Sets the scope to session-level. Optional parameter.
]);
取自Google文档: https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingCustomVariables#setup
我仍然坚持认为,对于您的用例,选择退出插件是更好的解决方案。
更新:考虑一下我认为你根本不需要setCustomVar或自定义cookie。让您的员工通过以下链接访问您的网站:
mywebsite.com?utm_source=allyourbasearebelongtous
然后转到配置文件设置并创建自定义过滤器,设置为排除,过滤字段“广告系列来源”,过滤模式“allyourbasearebelongtous”(或您为广告系列参数指定的名称)。
这也使用了cookie(标准谷歌cookie),但根本不需要任何自定义代码。广告系列来源参数在访问面向您网站的其他广告系列之前有效,因此,如果有人想要测试GA代码,则需要删除其Cookie或使用隐身模式(但与设置自定义Cookie或setCustomVar-没有区别)方法)。