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 ?
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.
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.
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).
navigator.userAgent
propertyIf 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"))
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
Select the Views, there this User Agent should be ignored > DONE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With