Google Analytics with WordPress – Exclude Your Own Visits

When I started to use Google Analytics last year, I was in a big LAN. To exclude my own traffic from Google Analytics, I created a filter to exclude a small range of IP addresses. Though it may wrongly filter out some visits of people in the same LAN, it’s tolerable.

Today I’m connected to the Internet by some DSL service of an ISP and the IP address changes from time to time, not limited in a C-class range. So I can no longer exclude my visits by simply creating a filter of IP address.

I searched the help system of Google Analytics, and got a method of excluding by cookie.

Yes, it’s great. But still it’s not convenient to set the cookie because cookies will expire one day or you may clear them by hand.

I was led to the wrong way since the beginning. Since we’re using Google Analytics on such a specific system – WordPress, we should discard the idea of excluding by IP and consider excluding by user.

Then I found some Google Analytics plugins for WordPress. For example, Ultimate GA. It provides an option of not adding analytics code to the page when it’s requested by a logged on user. And of course a lot of other great features.

I don’t want to use a plugin to slow down my WordPress for such a small requirement. Just surround your analytics code (usually in footer.php of current theme) with an “if” statement:

<?php if (!$user_ID) { ?>
...your Google Analytics code...
<?php } ?>

and it’s done.