As a website manager or owner, you probably don't want your Google Analytics account to track your own activity. Not only would this activity inflate your site's traffic figures, but you are likely to use the site fundamentally differently to other users: you might spend longer on a page, view more pages per session and so on. By including your own activity, you would skew all of these metrics.
One common approach to this problem is to build a filter to exclude all traffic from your IP address. In fact, Google Analytics Help has its own guide to doing this.
But the IP address filter is only useful if you have a static IP address, in other words one that is the same every time you connect to the internet. Even if you think your IP address is static, it may not be; IP addresses for Virgin Media domestic customers, for example, often don't change for months or years but are still technically 'dynamic'. This has caught me out in the past, leaving me with a non-functioning filter. I remained blissfully ignorant of the fact for quite some time, polluting my analytics data with my own visits all the while.
That's not the only limitation; if you access your website with your mobile while out and about, an IP address filter won't block your visits. All in all, an IP address filter is most suitable for a larger business with a fixed IP and a predominantly office-based workforce. For someone like a blogger, I would recommend excluding traffic from logged-in users instead. You will be logged in (as an admin) on your site: your users won't.
There are a few benefits to this approach: you won't be caught out by a sudden change in IP address; it works on any device in any location (as long as you are logged in); and you can still easily test your analytics at any time by logging out of your site. It also works well if you have more than one admin. However it isn't suitable if users are able to log in to your site, for example to change their preferences - or at least it would need to be adapted to take that into account.
These are the basic steps I usually follow:
And here's a more detailed guide to how I would accomplish each of these with a WordPress site.
I add the data layer to WordPress sites using the free Head, Footer and Post Injections plugin (which, incidentally, is what I also use to add the Google Tag Manager snippet). This saves me having to edit the theme files directly and means that my work won't be lost if the theme is changed in future.
I am neither a JavaScript nor a php developer, but here is a simplified version of the code I am currently using. (Also, I've recently learned that it is always better to use push() when interacting with the data layer, but I am yet to implement this, so please forgive me.)
1 2 3 4 5 6 | <script> var dataLayer = window.dataLayer = window.dataLayer || []; dataLayer = [{ 'loginstate': '<?php if(is_user_logged_in()) { echo "logged-in"; } else {echo "logged-out"; } ?>', }]; </script> |
Within a few hours, you should be able to start to see your Custom Dimension data in Google Analytics reports. The easiest way to do this is to add your Custom Dimension as a secondary dimension. Here's how:
Now it's time to add your Filter in Google Analytics. This is applied at the View level, rather than the Property level. Hopefully you have several Views - my standard setup is to have a Raw View, a Test View, and a Filtered View.
I would add any new filter to my Test View first, and then if all is well I would apply it to my Filtered View. My Raw View is left alone in case my filters go hideously wrong and I need to view the raw, unfiltered data.
That's it! You can test your implementation using the 'Realtime' reports in Google Analytics. Remember you have four different scenarios to test:
View | State | Should pageviews show in Realtime? |
---|---|---|
With filter | Logged in | No |
With filter | Logged out | Yes |
No filter | Logged in | Yes |
No filter | Logged out | Yes |
Neat guide.
But why not save the custom dimension and hits - and use your variables as an exception trigger to your GA tags along with other trackers such as Facebook, hotjar, etc...
Take care
/Daniel
Thanks Daniel! Until recently I used to do something similar to your suggestion and only trigger the GA pageview tag for non logged-in users. But then I became uncomfortable filtering out traffic before it reached GA. I prefer my GA 'raw' view to, as far as possible, show all traffic - even my own.
My new approach achieves this, but I admit it adds complexity and uses up a custom dimension! It is also not great if you are close to hitting sampling limits in GA and want to save some hits. So it isn't for every situation.