Author

Analytics advocate

SEO expert

User Experience passionate

Follow me on
Category | Google Analytics
Difficulty |

Exclude your and your team's traffic no matter where you are or what device you use

Excluding internal/employee traffic, is crucial for the accuracy of your Google Analytics. In this guide, I'll show you how to accomplish that, when the traditional method of filtering static IPs doesn't work.

When is this solution useful?

  • Your team works from multiple locations,
  • You are constantly on the move or work from different places,
  • When using your mobile phone network to test or work on your site (not WiFi),
  • When you are using IP Anonymization (anonymizeIp) required by the GDPR,
  • Your Internet Service Provider (ISP) changes your IP constantly, which means you have a dynamic IP.

What is a dynamic IP?

A dynamic IP address is an IP that is assigned automatically to any of your devices (smartphone, laptop, etc) and is constantly changing. The automatic assignment of IPs is done by your ISP.

If you are not sure if you have a static or a dynamic IP, monitor your public IP for a couple of weeks. You can easily check your current IP by searching "my IP" in Google.

  • A quick tip, if you see the long IP version (IPv6) its most likely that you have a dynamic IP.

If you are sure your IP doesn't change you can create a filter for static IPs in this other tutorial. Although I recommend you using this guide for a long term solution.

Excluding Dynamic IPs using GTM and Cookies

The process is a bit complex so I'll divide the instructions into 5 Steps, so you don't get lost:

  • STEP 1: Set the "Internal Traffic" cookie:
    • Using a bookmarklet
    • Using GTM
  • STEP 2: Create a Custom Dimension in GA
  • STEP 3: Assign the cookie value to the Custom Dimension in GTM
  • STEP 4: Create the filter for dynamic traffic in GA
  • STEP 5: Test your filter

If this is your first time working with this solution, to avoid problems use the exact same names on the guide, including spaces.

Requirements

To implement this solution first you need:

  • A (free) Google Tag Manager account and a basic tag that fires your Google Analytics code
    If you haven't done it follow this tutorial to add it manually to your site or if you use WordPress you can use this plugin.
  • [Optional] A test view in your Analytics - When you work with filters it is always recommended to have an unfiltered view and if you don't have much experience with filters create a test view.

Need help setting up a robust and reliable reporting for your website/business?

  • Filters for data quality 
  • User interaction tracking (events, goals)
  • E-commerce tracking
  • GDPR compliance
  • Google Tag Manager implementation
  • Integrations (Google Ads, Search Console, etc)
  • Custom reports (Dashboards, Data studio)
  • Monthly reporting and more...

Once you have the GTM account and the basic GA tag in place you can continue with the guide.

STEP 1: Setting the Cookie

If your work team is small less than 5 people the option a) bookmarklet should be enough. If you have a large team or do extensive testing across multiple devices, then the option b) GTM is for you.

You can even use both for different situations.

A) Setting a Cookie with a Bookmarklet

STEP 1A

Bookmarklets are extremely helpful mini-applications that provide additional functionalities to your browser right from your favorites bar. I used it all the time to simplify some common tasks.

In this case, I created this bookmarklet to insert the "Internal Traffic Cookie" with just one click.

  • Drag this button (bookmarklet) into your favorites bar +InternalCookie
  • If you know javascript this is what the bookmarklet contains:
    javascript:function setCookie(cname, cvalue, exdays) { var d = new Date(); d.setTime(d.getTime() + (exdays*24*60*60*1000)); var expires = 'expires='+ d.toUTCString(); document.cookie = cname + '=' + cvalue + ';' + expires + ';path=/'; } setCookie('InternalTraffic', 'true', 365); alert('Cookie: InternalTraffic\nValue: TRUE\nDomain: ' + window.location.hostname)

     

The second option.

B) Setting the Cookie with GTM

STEP 1B

Now you have to move to Google Tag Manager

  1. Go to the GTM container you are using for your site.
  2. Click on New Tag and call it Set Internal Traffic Cookie
  3. Click on Tag Configuration, and select <> Custom HTML on the right panel 
  4. On the HTML box, enter the following script. This script will set the cookie that you will use later for the filter.
    <script>
    function setCookie(cname, cvalue, exdays) {
          var d = new Date();
          d.setTime(d.getTime() + (exdays*24*60*60*1000));
          var expires = "expires="+ d.toUTCString();
          document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
    }
    setCookie("InternalTraffic", "true", 365);
    </script>
  5. In the section below click on Triggering, click on the blue plus sign at the top right corner +
  6. Name the trigger as PV - Internal Traffic, click on Trigger Configuration,and select  Page View.
  7. Set the trigger to fire on Some Page Views and set the condition like this
    • 1st Dropdown select Page URL
      • Note: If you don't see Page URL on the list, on the left panel got to variables, click on the red button configure and enable it.
    • 2nd Dropdown select matches RegEX
    • Text Box enter /internal/$|\?internal$
  8. Save the trigger and then Save the tag.

Inserting the Internal Traffic Cookie into the browser.

  • a) Bookmarklet: Click the bookmarklet while you are on your site.
  • b) GTM: Open any URL of your site with the text ?internal at the end -> example.com/?internal

You need to do this:

  • In all the browsers you use to work on your site (mobile and desktop).
  • Whenever you clear the cookies on your browser.

STEP 2: Create a Custom Dimension in Google Analytics

STEP 2

Custom dimensions are a hefty feature to add additional information in Google Analytics. In this case, we will use it to determine if your visit is local or is an external user. To create it:

  1. Go to the admin section and on the PROPERTY column select Custom Definitions > Custom Dimensions. 
  2. Next click on the red button +New Custom Dimension   
  3. Configure the dimension as follows
    • Name: Internal Traffic
    • Scope: User
    • Check the active box Create custom dimension
  4. Click Create and in the next screen click Done. Back in the list screen, you will see your new custom dimension and next to it the Inde, remember this number because you will need it later.

STEP 3: Set Value for the Custom Dimension "Internal Traffic."

STEP 3
  1. In the GTM main screen click on Variables, under User-Defined Variables click NEW.
  2. Name your Variable Internal Traffic Cookie and click on Variable Configuration 
  3. Select 1st Party Cookie from the list on the right, enter InternalTraffic as Cookie Name and SaveCreate Dynamic Internal Traffic Variable GTM
  4. Now open the tag that inserts the Analytics tracking code on your site. 
  5. Under the tag, configuration click on More Settings and expand Custom Dimension 
    Note: if you don't see the More Settings option check the override settings box. 

  6. Click +ADD CUSTOM DIMENSION, on Index enter the number of your custom dimension (the number I told you to remember :) and on Dimension Value enter {{Internal Traffic Cookie}} and save the tag.  
  7. Lastly, click on PUBLISH in the top right corner of the main GTM window.Publish the GTM container

Note: If you want to test your tag before submitting the changes you can use the preview feature.

STEP 4: Create the Internal Traffic Filter for Dynamic IPs in GA

STEP 4

The last part of this solution is to create the filter in Analytics. Before setting the filter to your master view, I recommend you to try it first on your test view.

  1. Again go to the Admin Section of your Analytics, click on Filters under the View Column.
    Note: Don't use the option "All Filters" under the Account Column because you won't see the custom dimension there.
  2. Click the red button +NEW FILTER and enter "Exclude Internal Traffic (Dynamic IP)."
  3. Select filter type Custom and configure it as follows:
    • Filter Field search for Internal Traffic (This is the custom dimension you created before)
    • Filter Pattern enter true. Create Filter Dynamic IP Google Analytics

STEP 5: Activate and Test Your Filter

STEP 5

This should be done for every browser you use to work on the site mobile or desktop.

  1. Activate the filter either with the bookmarklet or by adding \?internal at the end of the URL of your site (example.com/?internal)
  2. Open the real-time report of the view where you applied the filter. You will see this in your report 
  3. Then go to any other page of your site (preferably one that is not commonly visited).
  4. If you don't see the next pages in the real-time report, then your filter is working! Congratulations :)

Next time you access the site from that browser your visit won't be counted in Analytics.

The cookie is set to last one year so unless you clear your cookies, you don't have to trigger it again.

Troubleshooting your filter

If you haven't work with cookies and GTM before chances are that you may miss something and the filter won't work.

The first thing to check is that the cookie was added to your browser:

  1. On Chrome.
  2. At the top right, click the three dotsMore and then Settings.
  3. Search for Content settings and click on it.
  4. Click Cookies at the top and then click on See all cookies and site data
  5. On the search box (the one for cookies, not the main one) enter your site name and click on it. (If you don't see it then there are no cookies for your site).
  6. Then find on the list InternalTraffic and expand it on the section content it should say true

If you don't see the cookie go back to the step 1.

In this page, you can see how to check cookies on other browsers

If your cookie is in place and is set to true and the filter doesn't work, check the setting in this order.

  • Make sure your filter in GA is correctly configured, Exclude > Field: Internal traffic > Filter pattern: true (step 4)
  • Make sure you are adding the custom dimension with the right index in your GA Pageview tag. (step 3)

This should cover the most common issues.

Let me know in the comments what do you think of this solution?

Author

Analytics advocate

SEO expert

User Experience passionate

Follow me on
Be the first to comment :)