Bas*_*asj 5 google-analytics google-analytics-api
有没有办法从具有特定用户代理的访问者中排除Google Analytics的所有属性和所有视图?
注意:它不适用于垃圾邮件/机器人防护(我已经检查了功能管理员>查看设置>机器人过滤>排除已知机器人和蜘蛛的所有命中),这是为了删除部分自己的流量.我无法使用IP过滤,因为我的IP一直在变化,我使用了很多设备(移动/台式机/笔记本电脑).我也不能使用cookies,因为我经常想把我的网站测试为一个随机的非登录用户.在深入探索Analytics UI之后,我没有找到任何结果.也许这需要API?
Bas*_*asj -1
(Google Tag Manager seemed a bit labyrinthic for me.)
I finally did this:
Use Custom UserAgent String extension (available for FF and Chrome) and set UserAgent to NoTracking (you can do it specifically for certain websites, i.e. your websites only, see options).
Add this in the PHP page, in the Analytics Javascript part:
<?php if ($_SERVER ['HTTP_USER_AGENT'] === 'NoTracking') echo 'if (false)'; ?>
Run Code Online (Sandbox Code Playgroud)
It looks like this:
<script>
<?php if ($_SERVER ['HTTP_USER_AGENT'] === 'MyselfXYZ12') echo 'if (false)'; ?>
(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','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-xxxxxxx-x', 'auto');
ga('send', 'pageview');
<script>
Run Code Online (Sandbox Code Playgroud)
This will have the effect of disabling the creation of ga object for your traffic only.
NB: I first thought about disabling GA code for my own traffic via Javascript with if (navigator.userAgent == 'NoTracking') but it seems that the UserAgent change thanks to the extension "Custom UserAgent String" has effect only after the page is rendered, which is too late.
| 归档时间: |
|
| 查看次数: |
1894 次 |
| 最近记录: |