2012-12-05 32 views
2

在工作中,我們有一個動態IP地址,因此通過IP排除內部流量對我們不起作用,我們必須在用戶瀏覽器中設置一個cookie,告知Google Analytics排除用戶流量與此cookie安裝。排除來自谷歌分析的內部流量

我們使用的Cookie是:

<body onLoad="javascript:_gaq.push(['_setVar','me_exclude']);">

這個cookie是在頁/ EX是不掛,那麼誰還會訪問它會是誰知道從排斥自己的人的唯一的人谷歌分析。

我在徘徊的是,您是否需要在此頁面上添加跟蹤代碼,以使排除Cookie能夠正常工作,或者是上面所需的行?

+2

更好地部署谷歌退出插件,在您的公司:https://tools.google.com/dlpage/gaoptout –

+0

感謝的是,我一直都在尋找那些之一很長一段時間,但只能找到鉻插件,並且都是firefox。歡呼聲 – sam

+0

您也可以通過IP完成此操作:https://support.google.com/analytics/answer/1034840?hl = zh_CN – TomFuertes

回答

0

我幾乎放棄了尋找答案,但後來發現這一點: https://developers.google.com/analytics/devguides/collection/analyticsjs/advanced#optout

1)讓自己網站上的一個虛擬頁面。例如: www.yourdomain.com/exclude-traffic.html

2)加入< META NAME = 「機器人」 內容= 「NOINDEX,nofollow的」 頭>,所以頁面不會被編入索引。

3)將腳本添加到頭標記內的跟蹤代碼上方。確保您更新UA-XXXXXXXX-Y值。您可以在管理 - >跟蹤信息 - >跟蹤代碼

中檢查您的GA代碼。4)在body標籤內添加鏈接。

5)打開頁面並點擊鏈接。

最終結果:

<!DOCTYPE html> 
    <html lang="en"> 
    <head> 
     <title>Remove My Internal Traffic from Google Analytics</title> 
     <meta name="robots" content="noindex, nofollow"> 
     <script> 
      // Set to the same value as the web property used on the site 
      var gaProperty = 'UA-XXXXXXXX-Y'; 

      // Disable tracking if the opt-out cookie exists. 
      var disableStr = 'ga-disable-' + gaProperty; 
      if (document.cookie.indexOf(disableStr + '=true') > -1) { 
       window[disableStr] = true; 
      } 

      // Opt-out function 
      function gaOptout() { 
       document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/'; 
       window[disableStr] = true; 
      } 
     </script> 
     <script> 
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ 
       (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), 
        m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) 
      })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); 

      ga('create', 'UA-XXXXXXXX-Y', 'domainname.com'); //now its changed to auto 
      ga('send', 'pageview'); 
     </script> 
    </head> 
    <body> 

    <h1>Remove My Internal Traffic from Google Analytics</h1> 
    <p><a href="javascript:gaOptout()">Click here to opt-out of Google Analytics</a></p> 

    </body> 
    </html>