Remove all traffic for a specific user agent

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

Note: this is not to prevent spam and bot (I already checked the Admin> Show settings> Bot filtering> Exclude all attacks from known bots and spiders) to remove some of my own traffic. I cannot use IP filtering because my IP address changes all the time and I use many devices (mobile / desktop / laptop). I also cannot use cookies, because often I want to test my site as a random, unregistered user . I did not find anything even after a deep study of the Google Analytics user interface. Perhaps this requires an API?

+4
source share
2 answers

( Google .)

:

  • Custom UserAgent String ( FF Chrome) UserAgent NoTracking ( -, -, . ).

  • PHP JavaScript Javascript:

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

    :

    <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>
    

    ga .

NB: , GA- Javascript if (navigator.userAgent == 'NoTracking'), , UserAgent "Custom UserAgent String" , .

-1

User Agent Google Analytics. , custom Javascipt. User Agent, GA . ( GTM).

  • Javascript. navigator.userAgent

enter image description here

  1. Google Analytics. . . - , , , . " ", . , .

enter image description here

GA, ( ). = > > .

User Agent , GA Behavior > Events > Top Events > (namend ( " " ))

enter image description here

User Agent Propertys Views. Admin > ( " " ) > "+ " > " " = "" > "" > " " >

enter image description here

"", > DONE

+2

Source: https://habr.com/ru/post/1679171/


All Articles