How To Stop GTM Tag If User Is Logged Into WordPress

When loading a script from GTM sometimes you need a script to not count logged in users. In this article, we’ll walk through how to stop a GTM tag from firing if the visitor is a logged-in user. The benefit of doing so is that it cleans up your data.

Another possible use case is with screen recording software. For example, the screen recording software, SmartLook, gives amazing details about how individual users are using your website. By watching your users interact with pages, you can tell if the users’ experience is good, confusing, or if an element should be removed. With that in mind, you probably don’t want to watch recordings of you or your team interacting with the software because you and your team already know how to use your website.

What you’d want to do is stop the script from loading if the user is logged in. This works because most of the time your team will visit the site as logged in users. If someone on your team isn’t typically viewing your site as a logged-in user, then they probably are less likely to be a developer; hence will act more like a real user.

 

 

In a nutshell, here are the steps to follow to stop a GTM tag from loading for users who are logged into WordPress:

  1. Add a “DOM ELEMENT” variable
    1. Selection Method = CSS SELECTOR
    2. Element Selector = body.logged-in
    3. Attribute Name = class
  2. Add the script from the tool you’d like to connect with (as a tag)
  3. Add a “PAGE VIEW” trigger with the following settings
    1. Trigger Type = Page View
    2. This Trigger Fires On = Some Page Views
    3. Variable = The variable you created in step #1
    4. Condition = EQUALS
    5. Then add “null” to the text field
  4. Use GTM preview to test the logged in and logged out view

Reference: See the Reference Article