How to exclude admin users from being tracked

One of the most used features of every Analytics plugin is the ability to exclude logged in and especially admin users from being tracked in Google Analytics or in other products.

As Google Tag Manager goes beyond being a tool to implement Google Analytics, users are able to exclude not only Google Analytics tags but eventually every tag that is included in Google Tag Manager. Using this, your activities on your site will not be included. You will not be included in any remarketing audience and your test conversions will be not counted in your ad accounts or analytics reports.

Why not block the entire GTM container if you wish to exclude admin users?

GTM4WP does not include any feature which prevents the GTM container code from being deployed on each of your pages. Instead of it gives you some fancy Data Layer variables which can help you to create exception triggers. This will give you the ability to exclude admin users.

There can be some tags and scripts in your container that needs to fire even if you are currently testing your site. Therefore it is better to use GTM triggers than blocking the whole container from loading.

Remember: we have to describe the case when you do NOT want to trigger certain tags. This means you have to think of your trigger in the reverse way. When the trigger conditions are being met during page load or other interactions, connected tags will not fire.

Simple case: exclude everyone logged in to your site

visitorLoginState is a very simple Data Layer variable: the value “logged-in” means someone is logged in to your site, regardless of the user role. The value “logged-out” means that an anonymous user is currently on your site. You can read the value using a Data Layer variable in GTM:

Create Visitor Login State variable to exclude admin users.

In many cases, a logged in user means an admin or an editor on the site which is enough to create a trigger:

Create trigger to exclude all logged in users.

It is important to use the Custom Event trigger type and to enter the .+ regular expression in the Event name input field. This will make sure that you are not blocking just the tags firing during page load, but the same event is also applicable to add to cart or other events that fire after the page has been loaded. The .+ regular expression is kind of an “every event” rule that will match all events on the site, including page load.

Exclude admin users or other user roles

There are cases where this is trigger not enough. Especially when you are using WooCommerce where your customers are being logged in as special WordPress users without access to the admin area. In this or any similar case you will need to identify the user role of the logged in user.

The Data Layer variable visitorType can help you to get this info. Create a new variable in GTM to access the value:

Create Visitor Tyoe variable to exclude admin users.

If there is no logged in user on your site, the value “visitor-logged-out” will indicate that state. If a WordPress user is logged in, the name of the role of the logged in user will be included. For admins this will be “administrator”, for lower level users this can be something else like “editor”. Using this info, you can create a trigger that matches only a specific user role:

Create trigger to exclude only admins

If you want to exclude other user roles you can use ‘matching regex (ignore case)’ instead of ‘equals’ and you can list the excluded roles using pipes: administrator|editor|whatever-userrole

Exclude but not while debugging

You may want to use a slightly modified trigger to exclude admins. If you are logged in but to check the tracking codes in your Google Tag Manager container, your goal is to allow tags to fire to see what is happening.

To achieve this, you should enable the Debug Mode built in variable in Google Tag Manager and include it in the trigger:

Enable Debug mode variable

This built in variable will evaluate to true while you turn on preview mode in Google Tag Manager and you open your website. Now you can include one more rule in your triggers:

Create trigger to exclude only admins but not while debugging your Google Tag Manager container

Add your exception trigger to tags

Now you only have to add this newly created trigger to each of your tags as an exception trigger:

Create exception triggers in Google Tag Manager