Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 210
Basj Avatar asked Jun 13 '17 16:06

Basj


People also ask

Can we block user agent?

A good way to block unwanted visitors to your site is by blocking specific user-agents. By blocking their User Agents, you will stop any traffic that contains the specified name in the user agent field. A “user agent” is a software agent that is acting on behalf of a user.

How do I remove employee traffic from Google Analytics?

From the Select filter type menu, select Exclude . From the Select source or destination menu, select traffic from the IP addresses. From the Select expression menu, select the appropriate expression. Enter the IP address or a regular expression.


1 Answers

In the first step you have to get the User Agent into Google Analytics. You can do this with the Tag Manager, by creating a custom Javascipt. This can return the User Agent and you can send it to GA with a custom Dimension or a Event. (It´s also possible to do this without the GTM).

  1. Log in to the Tag Manager and navigate to Variables
  2. Now we have to add a Javascript Variable. The User Agent is stored in the navigator.userAgent property

enter image description here

  1. Now we have to push this data into the Google Analytics Account. 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. As a Trigger we define "All Pages" so the event is fired with every pageview. The User Agent we send as a Event Label.

enter image description here

If you have this information in GA you can add a filter on Account Level (for alle Views and 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"))

enter image description here

In the last step we exclude the User Agent from all our Propertys and 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

enter image description here

Select the Views, there this User Agent should be ignored > DONE

like image 55
DanielS Avatar answered Oct 21 '22 03:10

DanielS