Filtering Yourself from Google Analytics


Google Analytics is a powerful and useful tool for anybody with any kind of website who wants to track their traffic.

I am going to attempt to show exactly how to add analytics and  also to filter yourself from the data if you have a self hosted blog using WordPress.

    1. Sign in to your Analytics account, and click Admin in the top menu bar.
    2. Select the account and property in the respective columns.
    3. Add tracking to your website
      1. Create a new profile on Google Analytics (if you have not already created one).
      2. Add the tracking code snippet to your website.
        1. Click Tracking Info under the property column
        2. Copy the tracking code snippet
        3. Now you have 3 options.
          1. Modify functions.php in your child theme and paste the following code.
            function sp_google_analytics_tracking_code() { 
            	?>
            	<script type="text/javascript">
            		var _gaq = _gaq || [];
            		_gaq.push(['_setAccount', 'UA-45876690-1']);
            		_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>
            	<?php
            }
            
            // include GA tracking code before the closing head tag
            add_action('wp_head', 'sp_google_analytics_tracking_code');
          2. Use the Insert Headers and Footers plugin and add it under the Scripts in header tab.
          3. Not Recommended: Modify header.php and paste the tracking code (from step 2.2) before the </head> tag</li> This method is NOT recommended because if the theme is updated you will lose your changes.
    4. Create a new html file and paste the following code.
      <meta http-equiv="”Content-Type”" content="”text/html;" charset="iso-8859-1?" />google analytics cookie excluder
      <!-- prevents indexing of this page by search engines --><meta name="ROBOTS" content="NOINDEX,NOFOLLOW" /><script type="text/javascript">// <![CDATA[
      var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-XXXXXXXX-X']); _gaq.push(['_setVar','no_report']); _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><meta name="robots" content="noindex" />
      <div align="center">
      <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
      <tbody>
      <tr>
      <td>
      <div align="center"><span style="font-size: xx-large;"><span style="color: #ff6600;">google analytics cookie excluder</span></span></div></td>
      </tr>
      </tbody>
      </table>
      </div>
      1. Get your Google Analytics Account ID and replace it in the above file
        1. Click Property Settings under the property column.
        2. Copy the code under Tracking ID. This will look something like UA-XXXXXXXX-X.
        3. In the above code, change UA-XXXXXXXX-X to the tracking id.
    5. Place the file anywhere in your site as long as it is under your domain, at root or in a subdirectory.
    6. Creating the Filter in Google Analytics
      1. On the Google analytics admin page click on Filter under the View option. Here is where you create your exclusion filter.
      2. Click on “New Filter”
      3. Give it a meaningful name
      4. In the Filter Type Select Custom Filter and leave it on the default Exclude
      5. In the Filter Field select User Defined
      6. In the Filter Pattern add no_report
      7. Save the filter
    7. Only carry out the next actions for computers you want to NOT be counted in Google Analytics.
      1. In the location field of your browser, open the html file on your domain.
      2. If everything works you should see a charcoal background with orange letters saying, “google analytics cookie excluder”
    8. Optional Test
      1. 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.

Leave a comment

Your email address will not be published. Required fields are marked *