[ad_1]
When I am logged in on a website as admin, i don’t want to have pixel. Since that I am editing stuff and sending false data to pixel. How to exclude admins from tracking on GTM?
Current tutorials on web are incomplete or really bad written – hard to follow.
[ad_2]
You could try wrapping your pixel code in the header.php file of your theme in an if [current_user_can( ‘manage_options’ )]) statement
<?php if(!current_user_can( ‘manage_options’ )): ?>
// Your html pixel code
<?php endif; ?>
Should be the most straight forward way to do it, and you can tinker with the capability you pass into the current_user_can() function (e.g. ‘edit_posts’).
Or you could also query for the actual user with [wp_get_current_user()]) and do it that way
<?php
$user = wp_get_current_user();
$allowed_roles = array(‘administrator’,’author’,’editor’);
if( !array_intersect($allowed_roles, $user->roles)): ?>
// Your html pixel code
<?php endif; ?>
Edit: Keep in mind for some pixels like GTM where there are 2 portions to installing the pixel (in the head, and in the body) you’ll need to do whichever option you choose in two different spots
Edit 2: Also keep in mind, down the road when you’re adding new tags with GTM or troubleshooting any of your other pixels you’ll need to sign out to actually see what you’re doing.