使用Cookie在Google Analytics中过滤数据



我正在尝试基于cookie为我的公司网站过滤谷歌分析数据。我不想跟踪内部流量,但我不能只根据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);
          })();

所以我的问题是,这些代码到底去了哪里?感谢你帮助我掌握饼干的新手技能。

不要使用setVar(已弃用),使用_setCustomVar:

_setCustomVar(index, name, value, opt_scope)

该调用位于_trackPageview调用之前。

标准GA中有五个自定义变量(高级中有50个),这就是"索引"名称"one_answers"值"应清除。

CustomVar对当前页面、会话或访问者都有效(在最后一种情况下,除非访问者等待六个月才能再次访问您的网站,否则在访问者清除浏览器中的cookie之前,CustomVar一直有效)。

像所有具有非同步GA代码的指令一样,这是在gaq数组上"推送"的,因此正确的调用是:

 _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.
   ]);

这是从谷歌文档中获取的:https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingCustomVariables#setup.

我仍然认为,对于您的用例,选择退出插件是更好的解决方案。

更新:考虑一下,我认为你根本不需要setCustomVar或自定义cookie。让您的员工通过以下链接访问您的网站:

mywebsite.com?utm_source=allyourbasearebelongtous

然后转到配置文件设置,创建一个自定义过滤器,设置为排除,过滤字段"活动来源",过滤模式"allourbasearebelongtous"(或您为活动参数指定的任何名称)。

这也使用了一个cookie(标准的谷歌cookie),但根本不需要任何自定义代码。活动源参数在他们访问针对您网站的另一个活动之前是有效的,因此,如果有人想测试GA代码,他们需要删除他们的cookie或使用匿名模式(但这与设置自定义cookie或setCustomVar方法没有什么不同)。

最新更新