How-to Exclude Logged in WordPress Users using Google Tag Manager

exclude logged-in users

Being able to exclude logged-in administrators from Google Analytics really cleans up your data and something we wanted to implement. I originally learned how to do this from the GTM4WP post. You should definitely check it out. I did find the post a little confusing so I created this post with more detailed steps and explanation. Let me know if the comments if you found it helpful.

In this post, we will walk you through how to exclude or “stop tracking” logged-in users from Google Analytics. We will be using Google Tag Manager (GTM) and the Google Tag Manager Plugin for WordPress (GTM4WP) to send information through the data layer using variables, triggers, and tags.

The best part –No Code Snippets Are Needed. If you do not know what all of these terms mean do not worry. However, a basic understanding of Google Tag Manager is helpful.

Defining Admin Users
In our example site we do not have a user community or different user roles. If a user is logged in then they are an administrator or editor and we want to exclude them from Google Analytics.  If you have a users that login and you want to track, you will need to vary the settings but for the majority of WP sites excluding all logged in users from analytics is the goal..

Before We Begin
Make sure that GTM4WP is installed, configured and sending over visitor data via Google Tag Manager to Google Analytics. If you are reading this article you most likely already have this done.

This how-to post will walk you through: 

  1. Creating a user-defined variable in Google Tag Manager
  2. Creating a new trigger and adding it to our new variable.
  3. Adding the new trigger to an existing Google Analytics Tag.
  4. Confirming everything is working correctly
  5. Publishing the new GTM Container.

For the first step we will be configuring GTM4WP to add variables to the data layer so they can be used by GTM. Now it is time to log into your WordPress dashboard.

  • Go to: WP Admin Backend > Settings > Google Tag Manager
  • Click the “Basic data” Tab
  • Click the “Visitors” Tab.
  • Once on the Visitors tab, check the “Logged in status” and “Logged in user role” boxes.
  • Click Save Changes at the bottom of the screen.

We have now configured GTM4WP to send the correct data to Google.

Note: Essentially we are adding some variables to the data layer. These variables provide details about if users are logged out or logged in. If they are logged in then the type of user they are is being identified.   Technically we do not need “Logged in user role” box checked, but it could come in handy should we want to track logged in user types.

Configure gtm4wp to exclude logged in users

Confirm the new data layer variable are Working
Want to confirm the change is working or curious about the change we made? It is super easy (and cool to learn)

After the two boxes are checked new variables are added to the data layer. 

To see this 

  • Right-click on a page or your site and go to View Page Source
  • Search for “gtm4wp.com” 
  • Look for the 3rd and 4th entry on the page, it will be the 2nd GTM4WP section on the page.

In the highlighted area you look for

  • visitorLoginState: logged-in
  • visitorType: administrator

You will need to be logged into WP to see these variables. By seeing these variable you know they will be passed onto GTM and GA.

Click the image to enlarge it.

 

In case you are interested, here is what the GTM code looks like WITHOUT the boxes checked.

Create a New User-Defined Variable

For this section we will create a varible that uses the Visitor Logged in State that is being sent from your WordPress site.

For this section log into your Google Tag Manager Account. 

  • On left click Variables
  • In the content area of the page look for the “User-Defined Variables” section, it is below the “Built-in Variables section”
  • In “User-Defined Variables” section click “New”
  • A screen will slide out
GTM Create New User Defined Variable

You are now in a new variable window

  • In the upper left corner click and replace “Untitled Variable” with a new name. In our example we called it “visitorLoginState”
  • Once the variable has a new name, mouse over the :Variable Configuration” box (center of the screen), a pencil icon should appear.
  • Click the pencil icon to edit the new variable.
  • After clicking the pencil icon a new window will slide out.
New Variable Filled in

In the “Choose variable type screen, we will select the variable type

  • Look for the “Page Variables” section
  • Select “Data Layer Variable”
You will be taken back to the variable configuration screen 

You will now be at the screen to actually configure our new variable

  • In the Data Layer Variable Name box enter “visitorLoginState” (side note: this is the variable created by GTM4WP in the previous state)
  • Click the “Set Default Value” check box
  • Enter the Default Value to “logged-out”
  • Click “Save” in the upper right corner
You will then be taken back to the variables screen
Configure The Variable

Congratulations! You created and configured a new User-Defined Variable. Now it is time to create a trigger and add the variable to the new trigger.

Create a New Trigger

Now it is time to create a new GTM trigger. 

  • Go to the Workspace tab in Google Tag Manager
  • Click Triggers on the left
  • Click “New” on the right side of the screen 
  • A new screen will slide out
Create New GTM Trigger

Now that a new window opened up, it is time to name our new trigger.

  • In the upper left corner click and rename the trigger, we called it “Block logged in users”
  • After (re)amed the trigger, mouse over the Trigger Configuration and click the Pencil icon.
  • A new screen will slide out
Name New Trigger

You are now in the “Choose trigger type” screen. 

  • Look for the Page View section
  • Click “Page View”
  • you will be taken back to the Trigger Configuration Screen
Choose GTM Trigger Type

Now we will select the pages for the trigger on. 

  • In the “This trigger fires on” select “Some Page Views”
  • A new box will roll out
  • Click the Click Classes, and a select list will rollout.
  • Select “visitorLoginState” (this is the variable we just created)
Select GTM Trigger Variable

 

Now that we have the variable selected, it is time to set the parameters.

  • Set the middle box to “equals”
  • In the last box enter the value of “logged-in”
  • Click Save in the upper right corner. 
  • You will be taken back to the Triggers top level screen.
Set GTM trigger equal value

Debug Mode Exception (optional)

This next section is optional. We walk through excluding Logged in Users while ALLOWING Logged in users working in Google Tag Manager

Since you are usually logged into the WP site when you are working with Google Tag Manager, the above settings will keep you viewing your GTM results. To avoid this we add an exception to the exception to excluding logged in users.

To allow logged in users who are testing Google Tag Manager:

  • Go Back to Variables
  • Click Configure
  • A new screen will slide out
select variables configure

We are now in the “Configure Built-in Variables” screen. Here we select which variable to enable for use in Google Tag Manager. Here we will enable “Debug Mode”

  • Scroll Down to the Errors Section
  • Check the “Debug Mode” Box
  • Click the “X” back in the top left of the screen
  • You are now taken back to the main Variables screen
select-debug variable in Google Tag Manager

It is now time to add the debug mode exception to our trigger. To do this

  • Click the Triggers Link on the left side of the screen.
  • Click the “Block logged in users” trigger we just created.
  • The edit screen for “Block logged in users” will open up.
select trigger to modify

You are now in the Trigger Configuration screen.

  • Mouse over the Trigger Configuration in the center of the page
  • A pencil edit icon will apear
  • Click the Pencil icon
  • Edit mode will open up
click pencil icon

Once the edit mode opens up you will see a + sign in the bottom right of the screen. This will allow us to add the debug mode exception rule.

  • Click the Plus sign in the lower right corner
  • A new condition line will open up
click plus to add debug line

The new line has opened up and now we need to set the conditions.

  • In the first dropdown select “Debug Mode”
  • In the 2nd dropdown select “equals”
  • In the third dropdown type in “false” (no quotes)
  • Click outside the edit box to leave edit mode.
  • You are now back at the Trigger configuration page
enter debug mode conditions

We are now back at the trigger configuration screen and we need to save our changes.

  • In the upper right hand corner click “Save”
  • You are now back at the main Trigger Screen
click save

Congratulations! You have just added a condition that allows administrators in debug mode to have the triggers fire.  

 

To confirm

  • When you are logged into WordPress and have Google Tag Manager open in debug mode, you ARE counted
  • When you are logged into WordPress and NOT working with Google Tag Manager you ARE NOT counted.
  • This variation is not needed but it does make it easier when working in GTM

Add the Trigger Analytics Tag as an Exception

Now it is time to add the trigger to the analytics tracking tag.

  • On the left click “Tags”
  • Then select your “Google Analytics Tracking Tag
  • A new screen will then slide out
In the image below the Tag is called “Universal Analytics 2”
Click Tags and Select Analytics

In this new window, you will see a Tag Type of Universal Analytics, and in the Triggering section, you will most likely see a firing trigger of All Pages.

  • Mouse over the triggering area and click the pencil icon
  • Click Pencil Icon to edit “Triggering”
  • The triggering section will expand just a bit.

Once you click the Triggering Pencil Icon, the area will become editable. You will see the plus sign appear on the right side of the triggering window.

  • Click the Add Exception Link
  • A new screen will slide out
Click Add Exception

In this new screen, you will choose the trigger to act as the exception to our “Fire on All Page” trigger.

  • Select the “Block logged in users” 
  • After selecting you are taken back to the triggering configuration page
Note: This is the trigger that we created a few steps earlier.
choose exception trigger

You are now back at the “Tag Configuration” page. Now there is an exception added to the firing trigger.

  • Confirm that you now the exception has been added
  • Click Save
  • You are taken back to the Tag page
Confirm Exception For Firing Trigger

Congratulations we are all set to now start test and publish the changes!

Test & Publish Your the Updates

For testing and publishing, you should be familiar 

If you want to go into the preview mode click the preview button

Once your updates are tested and ready to go, click the “Submit” button to start the publishing process.

  • Click Submit
  • A new screen will slide out
Click Submit to publish changes

In the Submit Changes Screen enter the values for Version Name and Version Description. Here are the values I used for this site:

  • Version Name: Block Logged in Users
  • Version Description: Adds an exception to not track logged in users
  • Click “Publish”
Publish Changes

After clicking Publish, Tag Manager will take you to the “Versions” tab.

 

Contratulations! You are now blocking logged in users in your WordPress Website from your Google Analytics reports.

As with all things analytics, it is good to check your reports for a few days to confirm everything is working and reporting correctly

Additional Resoureces

Here are some other great posts that helped me learn this concept and the steps to complete it.

How to Exclude Admin Users From Being Tracked by GTM4WP