Posts Tagged ‘Free From Corruption’

How to exclude yourself from Google Analytics with WordPress

Without data we’re only guessing so it’s critical that we not only have great data to make decisions with but also that the data we do have is as free from corruption as possible. With that in mind if you run a WordPress website and Google Analytics, you’re most likely skewing your data without realizing it by visiting your own website.

To stop yourself from being counted as a visitor, all you need to do is add a simple piece of code to your websites header.php file that will read:

 

[source lang="php"]<?php
if (is_user_logged_in() == 1) {
if (wp_get_current_user()->ID == 1) {
setcookie("analyticsexcludeme", "analyticsexcludeme", time()+3600);
}
};
?>[/source]

Make sure the code is placed above the Google Analytics code (which I always like to place in the footer of my websites anyways). Once this code is placed in your header file, your website is updated but you’re not finished yet!

 

The code is only the first part, it’s what tells Google that you’d like to be excluded but now we need to actually exclude you.

Log into your Analytics account and click Analytics Settings.

Next, open the Filter manager (very bottom right corner).

Finally, add a new Filter with the settings:

analytics exclude me How to exclude yourself from Google Analytics with WordPress imageThis will tell Google to exclude all visitors who have the cookie “analyticsexcludeme” in their web browser, the same cookie we set earlier in the header code section of this tutorial.