删除特定用户代理的所有流量 [英] Remove all traffic for a specific user agent

查看:89
本文介绍了删除特定用户代理的所有流量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法可以从 Google Analytics的所有属性和所有视图中排除特定用户代理的访问者?



注意:这不是垃圾邮件/僵尸程序的预防(我已经选中了功能管理>查看设置>僵尸程序过滤>排除已知僵尸程序和蜘蛛的所有命中),它将删除自己的交通的一部分。我无法使用IP过滤,因为我的IP一直在变化,而我使用了许多设备(移动/台式机/笔记本电脑)。我也不能使用cookies,因为我经常想将我的网站作为随机的未登录用户进行测试。即使深入了解Analytics UI,我也没有发现任何内容。也许这需要API?

解决方案

(Google Tag Manager对我来说似乎有点迷糊。

我终于这样做了:


  • 使用自定义UserAgent字符串扩展(可用于FF和Chrome)并将UserAgent设置为 NoTracking (你可以专门为特定的网站,也就是你的网站,请参阅选项)。


  • 在PHP中添加页面,在Analytics Javascript部分:

     <?php if($ _SERVER ['HTTP_USER_AGENT'] ==='NoTracking ')echo'if(false)'; ?> 

    看起来像这样:

     <脚本> 
    <?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)})窗口,文档,'脚本','https://www.google-analytics。 COM / analytics.js的, 'GA');
    ga('create','UA-xxxxxxx-x','auto');
    ga('send','pageview');
    < script>

    这将会禁用创建 ga

    注意:我首先想到的是通过禁用GA代码来实现自己的流量。 Javascript with if(navigator.userAgent =='NoTracking')但是由于扩展名Custom UserAgent String的改变,UserAgent似乎只有在页面呈现,这太迟了。


    Is there a way to exclude, from all properties and all views of Google Analytics, the visitors with a specific user agent?

    Note: it's not for spam/bot prevention (I already checked the feature Admin > View settings > Bot filtering > Exclude all hits from known bots and spiders), it's to remove a part of own traffic. I can't use IP filtering because my IP changes all the time, and I use many devices (mobile/desktop/laptop). I also can't use cookies, because often I want to test my website as a random non-logged user. I didn't find anything even after exploring deeply the Analytics UI. Maybe this requires API ?

    解决方案

    (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)'; ?>
      

      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>
      

      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.

    这篇关于删除特定用户代理的所有流量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆