Exclude All Wordpress Internal Traffic from Google Universal Analytics

Let's start

We have been able to exclude GA code from running for logged in users. But what if we also want to exclude the future sessions of the internal users when they visit as logged out users? This is helpful because wordpress frequently logs out users and our main objective is to filter out internal users from our GA traffic regardless of whether they are logged in or not.

This can be done by setting a user scope custom dimension on the user. This would then exclude all future sessions of the particular user from GA.

Create Custom Dimension

Login to Google Analytics > Select your profile > Go to Admin > In the property row select Custom Definitions > Custom Dimensions > Click New Custom Dimension

On the next page click Add a name (I used User Type) > Set scope to User > Hit Create > then Done

On the screen now note the Index of your newly created custom dimension. Got it? Next Within your wordpress template add this to footer.php

<?php if ($user_ID) : ?>
<script>
// enter index below
var dimIndex = 1;
 
// set custom dimension
ga('set', 'dimension'+dimIndex, 'Registered User');
// send data to GA
ga('send', 'event', 'User Type', 'Registered User', {'nonInteraction': 1});
</script>
<?php endif; ?>

On the line var dimIndex = 1; change the number to the Index of custom dimension you created.

Filter Users With Custom Dimension Value

Finally create a filter in your google analytics view to exclude Users who have this custom dimension value.

Going forward any user who has logged in to the site once will be excluded from your Analytics view. This can be used in conjunction with IP exclude filters to make sure any internal users are excluded.

 Filter Custom Dimension

Filter Custom Dimension

ps. this will exclude any users that have logged in once. So if you are a membership site or a wordpress site which creates accounts for external users this method should not be used.

Don't miss out when new resources launch

Our customer analytics experts share wisdom only once a month

Share now
We are customer-analytics consultancy that transforms messy data into actionable insights that will help you grow your company and make better data-backed decisions.