Support » Your WordPress » TUTORIAL: Filtering Yourself from Google Analytics

  • Resolved Garrett Cobarr


    Google Analytics is a powerful and useful tool for anybody with any kind of website who wants to track, in granular detail, their traffic. Furthermore, if you are into Google’s various revenue streams for traffic, its essential. But there is a huge problem for most people, the documentation sucks. I refer to their reference about how to exclude yourself, or any other people working on your site that you do not want to count, “How do I exclude my internal traffic from reports?

    The section most relevant to WordPress users is at the bottom, “To exclude traffic by Cookie Content” This is the method required for dynamic websites. Unfortunately, the information is sparse. Also, I have discovered that the explanation is deprecated and incorrect.

    I had asked in the forums about this problem, “Google Analytics and WordPress” I received a number of helpful answers and I installed,”Yoast GA plugin.” The problem with the Yoast plugin and I would believe the other 2 would be that is almost impossible to solve this issue from within WordPress. It has to be solved on a per computer/user basis.

    I am going to attempt to show exactly how to carry out this task, I promise to be gentle, some things are a bit technical. I want to credit my friend David Rosenfeld for doing most of the heavy lifting on this research.

    1. First step, if you do not have a Google Analytics account, you need to create one. If you have a gmail account or some other Google account you can start with that.

    2. You need to get the cut code snippet example and paste it into the header.php file of your of your WordPress site. Paste the snippet right before the line</head> Follow the other directions in Google help here, “Getting Started with the Asynchronous Snippet -The Snippet

    3. Do not forget to get your Google Analytics Account ID here Overview ยป WholeThinking ( Edit account settings ) while you are still logged into your account. Cut and paste that number into the code where it says, “UA-XXXXX-X” Once you have completed these steps you can save and close your header.php file.

    4. Go to “Analytics Settings > Create New Website Profile” and create a profile, read more about that here, “Accounts and Profiles

    Let’s take a breath. You have now done everything needed to create a Google account, inserting the code snippet so that your site is followed and a Profile to do just that. If you did nothing else you could watch your site’s traffic and study all the nitty gritty details ad infinitum. But…

    The whole point of WordPress is to keeping adding content. Whether you are the captain of your rowboat, acting as both admin and author, or run a site with multiple admins and authors you need to make sure that all of these contributors are not counted in Google Analytics. You and all your contributors will skew your data, giving you inaccurate results. 10 to 1, that huge readership in your hometown, is you working on your site, not other viewers. So let’s get you out of there…

    You need to accomplish 2 things: create a filter in your GA profile that catches you and cookie on your computer that tags you in such a way that the filter sees you as unique from viewers. Let’s do the hard part first, creating the cookie.

    1. Use any text editing app you want, just make sure that you save it in Plain Text, not RTF or any proprietary format. Cut and paste the code located in the Pastebin example into your text doc.

    2. You need to change 2 pieces of data in the code. On line 13, change “Account ID” to your GA account ID. On line 26, change “your_value_here” to some unique value of your creation. Keep it simple enough, nothing but letters, numbers and underscore. I am not sure if this is case sensitive.

    3. Once you have replaced the data with your unique information, save the file with any name you want. Make sure the extension of the is .html Place the file anywhere in your site as long as it is under your domain, at root or in a subdirectory.

    4. Go back to the first page of Google Analytics, in the lower right, under the “Website Profiles” list, click on the link “Filter Managerยป” Here is where you create your exclusion filter. Click on “+ Add Filter”

    5. Give it a meaningful name, click on “Custom filter” and leave it on the default “Exclude”. In the popup menu choose, “User Defined”. Place the exact value you put in your HTML file in the field, “Filter Pattern” Set “Case Sensitive” to what works best for you but your values must match exactly. Below, in “Apply Filter to Website Profiles” assign your filter to your profile. Don’t forget to click on the button, “Save Changes”

    OK, everything should be set, now for the sexy part…

    1. Only carry out the next actions for computers you want to NOT be counted in Google Analytics. In the location field of your browser, set the path to your HTML file, domain > sub directory > file name. Press enter, return on keyboard to load the page. If everything works you should see a charcoal background with orange letters saying, “google analytics cookie excluder” If you see this, the page should have worked and set the cookie on the computer you want excluded from GA. Don’t get rid of this page yet.

    2. TEST. Go to the area of your browser that shows cookies. Search for the value you set in the cookie. If you find it the value is set.

    3. Save a bookmark of your excluder page. In case you clear your cookies, this is a quick way to reset it. It is also a quick way to get to the place to cut and paste the link for others who work on your site that you also want excluded.

    4. Testing to make sure you are being excluded in the GA report is a bit more complicated. First you need 24 hours to see the data. I am able to see that I am not counted because my site is brand new and announced. Being in a big town can make an existing site hard to test, being in a small town makes it easier.

    If over a few days or week you are suspicious of your numbers and think your are still being counted. Go back and check everything, also make sure you did not miss any of your contributors, authors and admins. In my case that was 2 people with 4 machines, we had to set all of them.

    A few notes on the file…

    Line 8, this insures that your file (which is a page) is not indexed by search engines.

    Lines 30 to 44, You can modify this part in any way you wish. This is simple feedback. In our case, we have several sites on a managed VPS. We all contribute in different ways to each other’s sites. To insure that we hit the right page and set set the right cookie we place the domain name in line 36, replacing, “google analytics cookie excluder” If you make a mistake an set a cookie on the wrong machine, delete the cookie and it will be counted.

    So I hope this helps. I fiddled about for almost 2 months before I got to this solution. I really encourage anyone who would like to improve or suggest further improvements to place them here as comments. If any future generations search for Google Analytics, here it all shall be.

    Not that you would see this in action, but it iss buried in the backend of my site WholeThinking If you do go there, I will see it in my Google Analytics. ๐Ÿ™‚

Viewing 15 replies - 1 through 15 (of 19 total)
  • Moderator Jan Dembowski


    Brute Squad and Volunteer Moderator

    Interesting and lengthy post, but here is not really the place to put a blog entry.

    Write this up on your blog and people will find it using the power of The Google. Here this will get lost in the crowd and you’ll help other people more.

    PS. Nice layout on your blog, that theme really works.

    Jan, thanks for the compliment on the my site’s design layout.

    For people using WordPress and wanting to add Google Analytics to the mix there really is no one place to go, especially when it comes to filtering yourself from a dynamic website.

    I posted 4 to 5 separate questions in the GA forums and never received any kind of useful solution. The post above is the work of 2 people over the coarse of a month and a half of many searches and much reading, most of it not on Google help.

    I solved the problem for myself and could have left it at that but a lot of nice folks have given me some very important solutions in the WordPress forums, some short and some long. There is not a lot of opportunity for me to give back as I am still new to WordPress. The post above is an attempt at thanking those who helped me by hopefully helping some others avoid the slog I went through.

    My site is a long form journalism about technology and its relationship to culture, not really a blog and not really a how-to guide. So I had no place to put the post except in the place that most folks come for WordPress solutions.

    I have to ask, why was this post moved from the “How To” to this section?

    Because, ideally, this post does not belong in a forum. Perhaps you could consider adding it to the Codex instead?

    Wow, esmi Codex? I would be happy to see it there. I am new to WordPress and assumed that Codex was for officially approved material. How would I go about that?

    The main thing is having this information available to people to use.

    I would most likely rewrite it to be more thorough and complete.

    assumed that Codex was for officially approved material

    Anyone can contribute to the Codex – although quality does count. ๐Ÿ™‚

    The other concept that you need to understand is that, as the Codex is essentially, a wiki, any other Codex contributor can (and sometimes will) edit, prune and otherwise amend your contributions.

    How would I go about that?

    I’d suggest that you start by logging into the Codex (you should be able to use the same username/password that you use on the forum) and drafting up the article as a user page. You’ll find a Help page and editing support documents available.

    As soon as your draft article is created, people will be able to start finding it via the documentation search

    When you’re happy with your draft, try joining the wp-docs mailing list and asking the list members to review your contribution and suggest where it might be best placed within the Codex.

    Thanks esmi.

    The other concept that you need to understand is that, as the Codex is essentially, a wiki, any other Codex contributor can (and sometimes will) edit, prune and otherwise amend your contributions.

    I hope so, I invited and expected this activity in the comments for the post but the Codex method would be much better, clearer and more detailed.

    I have copied my post and your comments, would it be appropriate to delete the main body of this post (or all of it) from this section? The post does not have much to do with showing off a completed WordPress site. My site is not really complete yet, I did not mean to have this be an invitation for feedback.

    The post is fine staying here for the time being. Later on, if you want feedback, you could post a url to the draft Codex article and ask for comments for the wider WP community. I’d guess that the Misc forum would be the best place for that.

    I agree that this forum isn’t ideal for the post either but I figured it would be seen by folks who have a WP site and are interested in using Google Analytics effectively. Added to which – it’s far quieter than the How-To forum. ๐Ÿ™‚

    I see, I agree… -:)

    Thank you for the info, it is very helpful and just what I need.

    I did everything you said, I even saw the grey page with the orange “google analytics cookie excluder” text.

    When I go to view my cookies however in FireFox it doesn’t display the cookie I set. Very confused as to why it has not picked up the cookie. Any help would be much appreciated, thank you.

    No problem, its great to help when I can, still fairly green about WordPress myself.

    My primary browser is Safari on a Mac but I have Chrome and Firefox for testing. ( I suggest that you make sure you install your cookie excluder on all your machines and all your browsers ( so easy to forget one ).

    I opened Firefox and chose my bookmark for the page setting the cookie ( yes I keep it in a bookmark for convenience, never know when you will have to reset it after a cookie clean out ).

    After setting the cookie by going to the page, I opened the Firefox Preferences and chose Show Cookies. Firefox shows cookies as a group for each site, click on the little arrow mark to open and show the cookies for your site. There should be at least 4, if not 5 of them.

    Firefox does not display values in each cookie until you select one of them. Safari does this at glance in columns. This may be why you did not spot your value, it may be actually be there but you have not seen it yet. The cookie that contains my value is named _utmv but I am not sure if it is the same for everyone.

    One way of testing in GA is setup 2 profiles: one with your filter and one with none. Watch over several days, you should see the one without the filter build numbers faster than the one with the exclusion filter.

    Hope this helps.

    Thanks for your advice, I just tried what you suggested and in the cookies there is absolutley no trace of my website.

    My website is

    here is where the file is uploaded, under the same directory of where my website is:

    There is no cookies displayed for, there are some for however the cookies are only from my hosts login screen.

    If you try replacing the url with my sites url then it gives me a “not found” page on wordpress, for instance:

    I am really confused with what to do now.

    Just to let you know I read your reply. I need to ponder this a bit, a step may have been missed. This may take me a few hours to get back to you.

    Not a problem at all, please take your time, I appreciate you helping me with this (:

    Thanks for the post! Wish I was able to find this hours earlier. ๐Ÿ˜‰

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘TUTORIAL: Filtering Yourself from Google Analytics’ is closed to new replies.