未使用基于Cookie的Google Analytics排除定义pageTracker

时间:2012-04-20 14:58:32

标签: google-analytics

按照此guide过滤Google Analytics中的管理流量

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Excluding traffic by Cookie Content</title>
<meta name=.robots. content=.noindex. />
<!-- Google Analytics Code -->
<script type="text/javascript">// <![CDATA[
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXXXXX-X']); //use real profile ID here
  _gaq.push(['_trackPageview']);
  _gaq.push(['_trackPageLoadTime']);
  (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);
  })();
// ]]></script>
<!-- Google Analytics Code -->
</head>
<body onLoad="javascript:pageTracker._setVar('filter');">
<h1>Excluding traffic by Cookie Content</h1>
<p>This page will set a cookie in your browser that will help Google Analytics filter the traffic that comes from your computer when using this browser.</p>
<p>Once you have this setup, don't forget to set a filter in Google Analytics.</p>
<p>You will need to visit this page only once.</p>
<p>However, if you clear your browser cookies, reinstall the browser or operating system, make sure that you revisit this page, so the cookie will be set again.</p>
</body>
</html>

我在Firebug中收到错误:pageTracker is not defined。我在一起修改了一个变种,它没有给出pageTracker错误,但我不确定我是否正确这样做。

<html>
<head>
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);//use real profile ID here
  _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);
 })();

 </script>
 <script type="text/javascript">
 try {
   var pageTracker = _gat._getTracker("UA-XXXXXXX-X");//use real profile ID here
   pageTracker._trackPageview();
   pageTracker._setVar('founders');
 } catch(err) {}
</script>
</head>
</html>

我上面的内容是否正确?

2 个答案:

答案 0 :(得分:1)

您似乎正在将传统风格分析(pageTracker._setVar...)与异步风格分析(_gaq.push...)混合使用。

您可以使用_gat._getTrackerByName()获取跟踪器对象的副本 - 尝试在您的身体onload中使用它:

_gat._getTrackerByName()._setVar('filter');

答案 1 :(得分:0)

@mike是对的,我最后使用Async混合技术,因为它有效;)

var _gaq = _gaq || [];     _gaq.push([&#39; _setAccount&#39;,&#39; UA-XXXXXXXX-X&#39;]);       _gaq.push([&#39; _trackPageview&#39;]);         _gaq.push([&#39; _setVar&#39;&#39; trackme&#39;]);

(function(){       var ga = document.createElement(&#39; script&#39;); ga.type =&#39; text / javascript&#39 ;; GA .async = true;           ga.src =(&#39; https:&#39; == document.location.protocol?&#39; https:// ssl&#39;:&#39; ht tp:// www&#39;)+&#39; .google-analytics.com / ga.js&#39 ;;               var s = document.getElementsByTagName(&#39; script&#39;)[0]; s.parentNode.i nsertBefore(ga,s);                 })();