简体   繁体   English

删除特定用户代理的所有流量

[英]Remove all traffic for a specific user agent

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.注意:它不是为了防止垃圾邮件/机器人(我已经检查了功能Admin > View settings > Bot filtering > Exclude all hits from known bots and spiders ),它是为了删除自己的一部分流量。 I can't use IP filtering because my IP changes all the time, and I use many devices (mobile/desktop/laptop).我不能使用 IP 过滤,因为我的 IP 一直在变化,而且我使用许多设备(移动/台式机/笔记本电脑)。 I also can't use cookies, because often I want to test my website as a random non-logged user .我也不能使用 cookies,因为我经常想以随机非登录用户的身份测试我的网站。 I didn't find anything even after exploring deeply the Analytics UI.即使深入探索了 Analytics UI,我也没有发现任何东西。 Maybe this requires API?也许这需要 API?

In the first step you have to get the User Agent into Google Analytics. 在第一步中,您必须将用户代理加入Google Analytics。 You can do this with the Tag Manager, by creating a custom Javascipt . 您可以使用custom Javascipt管理器通过创建custom Javascipt来执行此custom Javascipt This can return the User Agent and you can send it to GA with a custom Dimension or a Event. 这可以返回用户代理,您可以使用自定义维度或事件将其发送给GA。 (It´s also possible to do this without the GTM). (没有GTM也可以这样做)。

  1. Log in to the Tag Manager and navigate to Variables 登录跟踪代码管理器并导航到变量
  2. Now we have to add a Javascript Variable. 现在我们必须添加一个Javascript变量。 The User Agent is stored in the navigator.userAgent property 用户代理存储在navigator.userAgent属性中

在此输入图像描述

  1. Now we have to push this data into the Google Analytics Account. 现在,我们必须将此数据推送到Google Analytics帐户。 We could do this with a custom Dimension or a Event. 我们可以使用自定义维度或事件来完成此操作。 In this example we take a Event. 在这个例子中,我们采取一个事件。 As Action we send the Page Path - you don´t have to do this, but maybe it´s helpfull later for some reports. 作为Action,我们发送页面路径 - 您不必这样做,但是对于某些报告可能稍后有用。 As a Trigger we define "All Pages" so the event is fired with every pageview. 作为触发器,我们定义“所有页面”,因此每个页面视图都会触发事件。 The User Agent we send as a Event Label. 我们作为事件标签发送的用户代理。

在此输入图像描述

If you have this information in GA you can add a filter on Account Level (for alle Views and Propertys). 如果您在GA中有此信息,则可以在帐户级别添加过滤器(对于alle Views和Propertys)。 Filter Type = Custom > Select the Event or Dimension > Type the User Agent to exclude. 过滤器类型=自定义>选择事件或维度>键入要排除的用户代理。

We can see the User Agent of the Users visited our site now in GA Behavior > Events > Top Events > Search for the Event Category (namend in Tag Manager (in our case "User Agent")) 我们现在可以在GA行为>事件>热门事件>搜索事件类别(标记管理器中的名称和我们的“用户代理”)中看到用户的用户代理现在访问了我们的网站

在此输入图像描述

In the last step we exclude the User Agent from all our Propertys and Views. 在最后一步中,我们从所有的Propertys和Views中排除用户代理。 Admin > All Filters (In the Account column) > "+ Add Filter" > Filter Type = Custom > Exclude > Select "Event Label" in the Dropdown > specify the User Agent to ignore 管理员>所有过滤器(在“帐户”列中)>“+添加过滤器”>过滤器类型=自定义>排除>在“下拉列表”中选择“事件标签”>指定要忽略的用户代理

在此输入图像描述

Select the Views, there this User Agent should be ignored > DONE 选择视图,应忽略此用户代理>完成

Although this doesn't directly answer the question of how to block a user by user-agent string, it does I think solve the problem of how to remove your own personal traffic from being counted by Google Analytics虽然这并没有直接回答如何通过用户代理字符串阻止用户的问题,但我认为它确实解决了如何从谷歌分析中删除您自己的个人流量的问题

Google created a chrome plugin:谷歌创建了一个 chrome 插件:

Google Analytics Opt-out Add-on (by Google) https://chrome.google.com/webstore/detail/google-analytics-opt-out/fllaojicojecljbmefodhfapmkghcbnh Google Analytics 选择退出插件(由 Google 提供) https://chrome.google.com/webstore/detail/google-analytics-opt-out/fllaojicojecljbmefodhfapmkghcbnh

(Does require a chromium-based browser and appears you're using firefox but may help other users. Interestingly, there does appear to be a link which will download an xpi extension file if accessed from Firefox, but I'm not too sure about it https://tools.google.com/dlpage/gaoptout ) (确实需要基于铬的浏览器,并且您似乎正在使用 firefox 但可能会帮助其他用户。有趣的是,如果从 Firefox 访问,似乎确实有一个链接将下载 xpi 扩展文件,但我不太确定它https://tools.google.com/dlpage/gaoptout

For Firefox, I believe this one can block Google Analytics traffic:对于Firefox,相信这个可以屏蔽谷歌分析流量:

uBlock Origin https://addons.mozilla.org/en-US/firefox/addon/ublock-origin/ uBlock Origin https://addons.mozilla.org/en-US/firefox/addon/ublock-origin/

(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, ie your websites only, see options). 使用自定义UserAgent字符串扩展名(适用于FF和Chrome)并将UserAgent设置为NoTracking (您可以专门为某些网站执行此操作,即仅限您的网站,请参阅选项)。

  • Add this in the PHP page, in the Analytics Javascript part: 在PHP页面的Analytics Javascript部分中添加:

     <?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. 这将导致仅为您的流量禁用ga对象的创建。

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. 注意:我首先考虑通过Javascript使用if (navigator.userAgent == 'NoTracking')禁用我自己流量的GA代码,但似乎由于扩展名“Custom UserAgent String”而导致的UserAgent更改仅在页面为渲染 ,为时已晚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM