0

按照本指南过滤 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>

我得到错误:pageTracker is not defined在 Firebug 中。我拼凑了一个变体,它没有给出 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>

我上面的内容正确吗?

4

2 回答 2

1

看起来您将传统风格分析 ( pageTracker._setVar...) 与异步风格分析 ( _gaq.push...) 混合在一起。

您可以使用以下命令获取跟踪器对象的副本_gat._getTrackerByName()——尝试在您的正文 onload 中使用它:

_gat._getTrackerByName()._setVar('filter');
于 2012-04-20T17:47:11.053 回答
0

@mike 是对的,我最终使用了异步技术,因为它有效;)

变种 _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-XXXXXXXX-X']); _gaq.push(['_trackPageview']); _gaq.push(['_setVar','trackme']​​);

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

于 2012-04-21T21:21:45.860 回答