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