This guide shows you how to stop GTM Kit from loading the container and pushing data layer events for logged-in users with specific roles. Most sites use this to keep internal admin and editor activity out of analytics.
What this does
When a user has any of the excluded roles, GTM Kit:
- Does not output the GTM container
<script>or<noscript>blocks. - Does not push the data layer events GTM Kit normally fires (page_view, e-commerce, form events, etc.).
For excluded users, the site behaves as if GTM Kit is not installed.
This is the right tool for keeping your own clicks out of analytics. It is not the right tool for consent-based blocking. For that, see Turn on Google Consent Mode v2 defaults.
Steps
1. Open General settings
Go to GTM Kit, General.
2. Find Exclude user roles
In the user-related section, the Exclude user roles field lists every WordPress role on the site. Pick any combination.
3. Save
The change applies on the next page load. If you have full-page caching enabled, the exclusion only kicks in for users who bypass the cache. WordPress logged-in users normally bypass page cache by default, so this works as expected for the typical case.
What roles to exclude
A reasonable default for most sites: Administrator, Editor, Shop Manager (if WooCommerce is active).
Roles you usually do not want to exclude:
- Subscriber and Customer. These are real visitors and you almost always want their behavior tracked.
- Author and Contributor if your site has many of them and they are real readers (some membership and community sites use these roles for normal users).
Be careful when assigning custom roles to staff. If you want them excluded, add the custom role to this list.
Verify it worked
- Sign in as an excluded user (e.g. Administrator).
- Open your public site in the same browser.
- View source. The GTM container
<script>should not appear. - In the DevTools console,
window.dataLayershould beundefinedor an empty array (depending on theme and other plugins).
Then sign out (or use an incognito window) and repeat:
- The container
<script>should appear. window.dataLayershould populate withpage_viewand other events.
Common issues
The container still loads even though I excluded my role. You probably bypassed the role check via a cached page. Hard-refresh (Cmd or Ctrl + Shift + R), or temporarily disable page caching while you verify.
An “Exclude user roles” change is not respected after a custom role plugin update. Custom role plugins occasionally rename or remove roles. Re-open Exclude user roles and re-pick the roles you want excluded.
You want to exclude a single user, not a whole role. That is not supported via the UI. You can do it in code by hooking the gtmkit_container_active filter:
add_filter( 'gtmkit_container_active', function ( $active ) {
if ( get_current_user_id() === 42 ) {
return false;
}
return $active;
} );
This disables container injection for that user only. Note that the filter only suppresses the container; data layer pushes still fire.