Category Archives: Google Analytics

How to exclude your visits in Google Analytics

It’s important to exclude your own visits when analysing your trafic via Google Analytics. The reason is obvious really, you do not want to contaminate your trafic data with your own visits, as this will not be a correct picture of your trafic data.

There are a number of ways to exclude your own visits in Google Analytics. I’ve tried using an ip adress, where you create a filter and exclude your own ip from a particular profile. The problem with this approach is when changing your computer or if you have a dynamic ip that constantly changes. Also, you need to create new filters for each ip you visit from. I’ve found that the best method for me is the cookie method. You create a html page on your website, with some JavaScript code that creates a cookie. You then create a filter in Google Analytics that excluded trafik when this cookie is active.

Copy/paste the code below to a file named exclude.html:

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <meta name="robots" content="noindex, nofollow">
  <title>Exclude My Visits!</title>
</head>

Exclude My Visits!
<!-- STEP TWO: Our One Line Piece of Code Goes In The Body Tag Below -->
<body onLoad="javascript:_gaq.push(['_setVar', 'test_value']);">
CONGRATULATIONS! YOU WON'T BE COUNTED BY YOUR OWN GOOGLE ANALYTICS NOW! HOORAY! JUMP FOR JOY!
<!-- STEP ONE: Your Google Analytics Code Goes Right Below This Line -->
<script type="text/javascript">// <![CDATA[
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'REPLACE WITH YOUR PROFILE NUMBER']);
_gaq.push(['_trackPageview']);
(function() {  var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
// ]]></script>
</body>
</html>

You now need to change a value at line 14. Replace the text with the Google Analytics profile you need to exclude the visits on. This will be something line UA-XXXXXXX-XX. Now upload this exclude.html file to the root of your website: www.yoursite.com/exclude.html – you could place it anywhere, but you’ll need to access it quickly in the future, so don’t place it somewhere you don’t remember.

Now login to your Google Analytics account and navigate to the filters settings:
Admin -> [account name] -> Filters -> Click on New Filter and input the following:

exclude-visits-analytics

It’s important that you type the “Filter Pattern” exactly as shown, as it relates to the code where we create a cookie with the value “test_value”. Before saving, remember to apply this filter to your profile.

Now you just need to visit the exclude.html file you’ve created. This will create a cookie on your computer. This cookie has a very long expiration date. Analytics will look for this cookie as we’ve created the filter, and will exclude the visits where this cookie is active.

Remember to visit exclude.html for each browser and computer you use, as the cookie will have to be set for all the browsers you use. But once you’ve done this, you don’t have to worry about your own site visits anymore.

You can now use this exclude.html file and copy/paste it to your other sites. Just remember to change the profile number and add the filter to the profile – easy!

If you have any questions or comments, go ahead and write those in the comments section below.