Exclude Admins From Google Analytics on WordPress

Google Analytics Dashboard

Google Analytics is an incredible tool that can track a phenomenal amount of useful information about your visitors. However, when your site is new, or if you just happen to spend a lot of time on there yourself, your numbers will be skewed as they are tracking you, the site admin, as well.

There’s two simple workarounds that will allow you to continue collecting stats from your visitors, but ignore any logged-in users (note that you must be logged in for both of these methods to ignore you).

Using A Code Snippet

The cleanest method in my opinion is to add a little code snippet in your footer.php as it does not bloat your installation with a plugin:

Open up your theme editor so that you can edit footer.php. Find the wp_footer() call (shown in line 01 below) and add the remaining lines below it, substituting your own Google Analytics tracking code (available from your Google Analytics dashboard – hit Edit next to the site in question, and then Check Status on the next page) in the lines highlighted in grey (which is my own tracking code).

It’s a very simple piece of code which wraps your Google Analytics code in a conditional statement, which checks whether the user is logged in or not. If they are, it skips over the tracking code, otherwise it uses it as normal.

Using a plugin (Google Analytics for WordPress)

Ignore WordPress Users from Analytics

Ignoring logged-in users for Google Analytics by using Google Analytics for WordPress

The Google Analytics for WordPress plugin is the only plugin you need when it comes to using Analytics with WordPress. Among the many options is one to skip over tracking logged-in users. You can also specify which roles you want to track (Authors, Editors, Administrators etc.).

On your Settings Page (select Settings > Google Analytics from the menu at the side of your dashboard), scroll down to the Advanced Settings section and the very first option is the one you’re interested. Select the minimum role that you want your tracking code to ignore (i.e. selecting Subscriber will ignore all logged-in users, but selecting Administrator will only ignore those with Administrator privileges). Save your settings and you’re away.

I visit my own site a lot to check things over and make design changes, so I get a lot of page hits that in my opinion should be omitted. Are you in the practice of ensuring that logged-in users are not being tracked for Analytics?

14 thoughts on “Exclude Admins From Google Analytics on WordPress”

  1. Nishadha says:

    I think using plugin is the most sensible thing to do because the plugin offer far more advantages as well. This want be a big problem for an established site though

    1. Dave says:

      Well you’re right, you do have more options with the plugin, but you have to decide whether you really need them. It’s always better to hard code it if possible – it’s the cleanest way to do it and the least burdensome for your blog.

  2. Ileane says:

    Hi Dave, this is a great tip! I’m using a different plugin called Google Analyticator but it basically has the same options. Hmmm…. maybe I should do a screencast for that one! Do you also use the Filters options in GA? I filter out my visits by IP from my home computer and from my work computer.

    1. Dave says:

      Hi Ileane,

      I think you should definitely do a screencast of Google Analyticator. Then we could link to one another’s?

      I used to use the GA IP filter, but I also access my site on the go, so my iPhone has a dynamic IP and it’s impossible to filter it. But excellent point. Certainly a good option for many users.

  3. Peter J says:

    Awesome, thanks for this, i don’t use analytics much anymore, but i’ve found that in wordpress, you can just install the plugin and it will do it for you.

    1. Dave says:

      Hi Peter, nice to see you here. I remember seeing a blog post from you, maybe on BizChickBlogs?

      Anyway, while WordPress is awesome for that very reason, I try and avoid plugins where practical, because it’s much better practice to hard code features into your theme.

  4. Ishan says:

    I use Google Analyticator plugin to exclude logged in users. It is quite good and brings lot of other features to table too. However, one disadvantage of having code excluded is that you can’t use site overlay. I have to use different browser for that, a little sacrifice.

    1. Dave says:

      Yes, someone else mentioned the Analyticator plugin to me. And that’s a good point about being unable to use Site Overlay – that hadn’t even occurred to me, since I don’t use that feature yet, but it’s maybe I should think about looking into in the future.

  5. Robb says:

    I do enjoy your ideas, thank you very much!

  6. Kimi says:

    Love the idea!!

    Have never thought about that, thanks!, tweeted!.

  7. Karl says:

    What if you use a page cache system? Won’t this risk to generate a cached version without Analytics’ code?

    Cheers!

    1. No, once you put that code in place, clear your cache, and then every subsequent page ever created (whether dynamic, or served from the cache) will have the Analytics code in it.

  8. yamaryam says:

    is this code still relevasnt with Universal analytics?

    1. Absolutely. Just use the new tracking code instead.

Leave a Reply

7ads6x98y