Stop Tracking Yourself in Google Analytics

Typically, once a WordPress installation is configured, one of the first things you install is your Google Analytics or Google Tag Manager script. This common practice can actually be quite frustrating on it’s own, and with a quick helpful tip, I’ll make sure that you have the proper information you need to make sure your data is accurate.

Why shouldn’t I track myself?

Well for one, why would you want to? You’re causing your numbers to go up while you are working on your website, and causing yourself stress when you think your startup is doing well, but after a couple of days in a row of not posting anything, you see your numbers drop significantly. Yes, if you are an active user of Analytics you know there are such things as session tracking, but for someone new, that relies on the dashboard figures, those numbers can really throw someones day off. Plus with this simple code, you can easily do this in a matter of minutes, vs hours customizing the dashboard and views. For someone who doesn’t have a dedicated team or the time to configure all of these, this is for you.

So how do I stop tracking myself in Google Analytics?

While there are many Google Analytics integration plugins on the Plugin Repository for WordPress that work perfectly out of the box, they don’t prevent tracking yourself, authors, editors, or developers. So a simple modification of your WordPress theme code will solve the issue. I would advise if you are not familiar with development that you backup your website before making these changes or have your developer implement these changes.

  1. Make sure you do not have Google Analytics plugin or code already installed on your website
  2. Go to Appearance -> Editor
  3. On the right side choose your theme
  4. Under theme files, click Theme Header
  5. After <head> add the following code
<?php
$gaDeny = array("PUT.UR.IP.HERE", "PUT.UR.IP.HERE");
if (!in_array ($_SERVER['REMOTE_ADDR'], $gaDeny)) {
?>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=YOUR-UA-ID-HERE"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'YOUR-UA-ID-HERE');
</script>
<?php } ?>

It would be best if you added your own tracking code found at Admin -> Property -> Tracking Code in your Google Analytics account.

Replace YOUR-UA-ID-HERE with your UA ID found in Admin -> Property Settings of your Google Analytics account.

Once this is added in, put the IP Address of your PC, Cellular Internet IP, and any other IP’s separated by ,’s in place of PUT.UR.IP.HERE. This will block the script from running on your networks, thus allowing tracking to be more accurate. As you start to grow, add your employee IP addresses into the mix, as even with session counts, you don’t want to be tracking anyone who could influence your numbers and cause discrepancies.

What if I use Google Tag Manager?

Preventing Google Analytics from tracking you, would be a separate step. If you apply this modification to Google Tag Manager, then any scripts configured in GTM will not be displayed to you.

How to implement on other platforms?

Whichever platform you are using, simply find your header theme file and add the above code below <head>, following all previous instruction.

One Reply to “Stop Tracking Yourself in Google Analytics”

  1. Thank you very much for this article I take good note

    Reply

Leave a Reply

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