Analytics my profession

SEO my passion

User Experience my obsession

Follow me on
Category | Google Analytics
Difficulty |

Excluding Your Own Traffic When Having Dynamic IPs in Analytics

One of the most common challenges in Google Analytics is excluding your own traffic when you don't have a static IP, whether it is because you are constantly traveling or simply because you have a dynamic IP.

I will show you a couple of methods I use when I face this scenario.

What is a dynamic IP?

A dynamic IP address is an IP that is assigned automatically to any of your devices: smartphone, laptop. The automatic assignment of IPs is done by ISP and it's called dynamic because it will often change.

When you will need to filter dynamic IPs:

  • You use your mobile phone network to test or work on your site (not WiFi)
  • Your ISP changes constantly your IP for whatever reason.
  • You are constantly on the move.

The opposite of a dynamic IP address is called a static IP address, the one that doesn't change. This is mainly the case of home/office networks although there are a few exceptions. If you have a static IP follow this other tutorial.

Do you need help configuring your Google Analytics? I can personally review and fix your Analytics configuration to make sure your data and settings are OK.

Ways to Exclude Internal Traffic with Dynamic IPs

I'll show you a couple of methods for excluding your visits when you have a dynamic IP.

  1. Using GTM and a Cookie (Recommended)
  2. Using a browser extension

Method 1: Excluding Dynamic IPs using GTM and Cookies (Recommended)

Note: For this solution, you need to have Google Analytics implemented through Google Tag Manager.

This method is a bit more complicated but is more efficient since it will let you control your traffic from Google Analytics instead of a 3rd party plugin.

I'll divide the instructions, so you don't get lost:

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

So let's start.

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

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.

To set the cookie on your browser:

The second option.

B) Setting the Cookie with GTM

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.
    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);
  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.

Insert the Cookie

  • 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 ->

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

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
  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 Index, remember this number because you will need it later.

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

  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 Save.
  4. Now go to the tag that inserts the GA tracking code on your site.
  5. Under the tag, configuration click on More Settings and expand Custom Dimension
  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 SUBMIT in the top right corner.

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

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
  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 Patternentertrue.

STEP 5: Testing your Filter

  1. Activate the filter either with the bookmarklet or by adding \?internal at the end of the URL of your site (
  2. Open the real-time report of the view where you applied the filter.
  3. Then go to any other page of your site (preferably one that is not commonly visited) or refresh the current one.
  4. If the last hit doesn't show on the real-time report, then your filter is working! Congratulations :)

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

Method 2: Excluding Dynamic IPs with a browser extension.

I recommend you to use this option only if you don't have another alternative. The reason is that sometimes you may need to do some tests, or simply you want to monitor internal traffic in a different view, and this extension won't allow that.

To prevent your visits from being recorded, you will use this extension.

Supported browsers
Chrome Firefox Opera
Safari Internet Explorer Edge

(These instructions are based on Chome and Firefox. If the functionality is different for other browsers let me know in the comments) 

  1. Once you installed the extension, go to your site and click on the little blue ghost at the top right corner, next to the address bar .
  2. Hover over the row that says Google Analytics and click on the lock icon ONLY .

Important Note: I don't recommend to use the "Block all" option. Like you, others rely on their analytics to make improvements on their site.

Be the first to comment :)