我几乎放弃了寻找答案,但后来发现:
https ://developers.google.com/analytics/devguides/collection/analyticsjs/advanced#optout
1)让自己成为您网站上的虚拟页面。例如:www.yourdomain.com/exclude-traffic.html
2)在head中添加<meta name="robots" content="noindex, nofollow">,这样页面就不会被索引了。
3) 在 head 标签内的跟踪代码上方添加脚本。确保更新 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>