A Guide on how to exclude Internal Traffic in Google Analytics 4

Note: Empower yourself and others by sharing this insightful article on LinkedIn or social media. Let’s build a well-informed community together. Need help? Reach out anytime. 

Introduction

In the realm of digital analytics, understanding and accurately interpreting traffic data is paramount for businesses aiming to make informed decisions. Google Analytics 4 (GA4) serves as a powerful tool for tracking website interactions, providing valuable insights into user behavior. However, the presence of internal traffic—interactions originating from within the organization—can skew data and compromise the reliability of analytics reports. In this article, we’ll explore the significance of distinguishing between external and internal traffic and discuss various methods to exclude internal traffic in GA4.

 

Understanding External and Internal Traffic

 

Before delving into methods to exclude internal traffic, it’s essential to distinguish between external and internal traffic. External traffic refers to interactions originating from external sources, such as website visitors, customers, or potential clients. Conversely, internal traffic encompasses interactions generated by individuals within the organization, including employees accessing the website for testing, development, or routine tasks.

 

Blocking internal traffic in GA4 becomes necessary to ensure the accuracy and reliability of analytics data. Internal interactions, if not filtered out, can distort metrics, such as website engagement, conversion rates, and user demographics, leading to misinformed decisions and inaccurate performance assessments.

 

Methods to Exclude Internal Traffic

 

Several methods can be employed to exclude internal traffic in GA4, each offering unique advantages and considerations. These methods include:

IP Address Filtering

Data Layer Parameters

Cookie-Based Exclusion

 

1) IP Address Filtering

One of the most common methods to exclude internal traffic involves setting up IP address filters in GA4. This approach entails identifying and specifying the IP addresses associated with internal traffic sources, such as office networks or remote employee locations. By configuring GA4 to disregard interactions originating from these IP addresses, businesses can ensure that internal traffic does not skew their analytics data.

 

This method does not work well if you have to enter many different IP addresses or if some IP addresses are not static (read: regularly changing).

 

Step 1. Define your internal IP addresses.

In Google Analytics 4, go to Admin > Data Streams and select your website stream. Then click Configure tag settings. Then click Show all and select Define internal traffic. Here you can create new internal traffic rules.

You can create separate rules for each IP if you are working with multiple IPs. Or you can create a regular expression and include multiple IP addresses there, like in the example below:

You can always enter “internal” in the traffic_type value field to simplify things. Then it will be enough to have one Internal Traffic filter in your GA property.

 

Step 2. Create a developer filter in GA4.

You might wonder what the difference is between a developer filter and an internal traffic filter in GA4. Both of them exclude data from the regular reports in GA4 (by checking different parameters).

The developer filter checks the debug_mode or debug_event parameters while the internal traffic filter looks for traffic_type.

But the key difference here is that you can see developer traffic in the DebugView of GA4, while the internal traffic is not displayed anywhere.

At least, that’s the theory. But I had mixed results here, and sometimes the internal traffic filter gets a higher priority than the developer traffic, and the debug view does not work as a result.

So, what can we do here? I’ll answer that in the next chapter. But first, let’s create a developer filter (because it is not ready by default). In GA4, go to Admin > Data Filters > Create Filter. Select Developer Traffic. Enter the following settings:

You can enter any name in the “Data Filter Name” field. Set this filter to Testing (for now). Save it. 

 

Step 3. Create a lookup table in GTM to override the traffic_type parameter.

This is where the magic will happen. In one of the previous chapters, I mentioned that GA4 automatically adds a tt=internal (traffic_type) parameter to all hits if they come from one of your internal IP addresses.

What we are going to do is to create a Lookup table variable that manipulates the value of the parameter. If we have the GTM preview mode enabled, then we will change the tt’s value to developer (or anything else). But if the Debug Mode is disabled, then we will not do any modifications and let the GA4 handle this.

First, create an Undefined variable. In GTM, go to Variables > New > Undefined and save the variable.

Now, let’s go to Variables > Configure (in the Built-in variables section) and enable the Debug Mode variable.

Finally, let’s go to Variables > New > Lookup table and enter the following settings:

Here we are using the Debug Mode variable as input. If the GTM preview mode is enabled, this variable will return true. Therefore, the lookup table variable will return the word “developer”. The Debug Mode variable will return false if GTM Preview mode is not used. Therefore, we will return undefined. That’s why we created the Undefined variable.

This is not the same as just entering “undefined” in the field. In JavaScript, “undefined” surrounded by quotation marks is a string (text). But undefined means no value. If you enter the word undefined in the Lookup table, that is a string.

Save the variable.

Finally, go to your Google tag and enter the following parameter: traffic_type. And its value should be the lookup table you’ve just created.

Step 4. Test the filters.

Now, it’s time to test. Enable GTM’s preview mode. And go to your website (obviously, you should be browsing from the IP address that is configured in the Internal Traffic section of your Data Stream). Go to the DebugView of GA4.

First of all, you should still be seeing hits coming from your device. Click on any event in the event stream and check the parameter traffic_type. Its value should be developer.

Also, in that same event, you should see the Debug Mode parameter too.

Remember: both filters (developer and internal) are not active yet. They are in testing mode, meaning the soon-to-be-excluded data is still visible in the regular GA reports.

When filters are in the testing mode, an additional dimension is added to them called Test data filter name. You can use it as a secondary dimension (or in Analysis Hub) to check how much of the data would have been excluded if the filters were active. You can also learn more about the filters here.

If this setup with the lookup table variable does not work, then you can consider not using it at all. The bright side of this is that at least your internal traffic will not be polluting standard reports and explorations.

The downside is that the debug view will not work (until GA4 fixes this). To avoid the downside, you could use a VPN service (like NordVPN, etc.) that can temporarily change your IP address. In that case, your company’s internal traffic is still excluded, and only you will be polluting GA4 data (but at least debug view will be working for you).

Alternatively, you can use a separate property for testing. I explain how to do that at the end of this blog post.

 

Step 5. Activate both filters

The last step is to activate both filters. Go to Admin (in GA) > Data Filters and set both triggers (Internal traffic and developer traffic) to active. You can do that by opening each filter, changing its Filter state, and then saving the changes.

Now, do the test once again.

  • Browse from the IP address that is defined as Internal
  • Have the GTM preview mode disabled. Browse your website (to send some events to GA4)
  • Check the DebugView. You should not be able to find your device and see new events coming from it.
  • Now enable GTM’s preview mode. Browse the website once again.
  • Check the DebugView. You should now be able to find your device and start seeing some data.

 

2) Data Layer Parameters:

Another effective approach involves leveraging data layer parameters to distinguish between internal and external traffic. By incorporating specific data layer variables or event triggers, businesses can tag internal interactions and exclude them from GA4 reports. This method offers flexibility and precision in excluding internal traffic, particularly in dynamic environments where IP addresses may change frequently.

 

Step #1. Getting the internal data parameter into the Data Layer

If that is possible, you should ask them to push the user_type (or traffic_type, or whatever) parameter to the data layer that could help you identify that the visitor/user belongs to your own company. If a visitor belongs to your company, then the parameter’s value should be internal. If a user/visitor does not belong to your company, no dataLayer.push should happen.

 

Here’s a sample dataLayer.push code that your developer could activate if the user/visitor belongs to your company:

 

<script>

  window.dataLayer = window.dataLayer || [];

  window.dataLayer.push({

    ‘event’: ‘traffic_type’,

    ‘traffic_type’: ‘internal’

  });

</script>

 

The event key is not required (but recommended). This code must be activated before the GTM Container snippet is loaded.

 

Then create a Data Layer Variable with the following settings:

Step 2. Create a developer filter in GA4

In GA4, go to Admin > Data Filters > Create Filter. Select Developer Traffic. Enter the following settings:

Set this filter to Testing (for now). Save it.

 

Step 3. Create a lookup table in GTM to override the traffic_type parameter

Go to Variables > New > Lookup table and enter the following settings:

Here we are using the Debug Mode variable as input. If the GTM preview mode is enabled, this variable will return true. Therefore, the lookup table variable will return the word “developer”.

 

If GTM Preview mode is not being used, the Debug Mode variable will return false. Therefore, we will return the value of the Data Layer Variable that you created in the first step.

 

If the data layer contains the traffic_type key, then its value will be sent to GA. If the key does not exist, then it will be set to undefined (meaning that GA4 will not send the traffic_type key at all).

 

Save the variable.

 

Finally, go to your Google tag and enter the following parameter: traffic_type. And its value should be the lookup table you’ve just created.

Step 4. Test the filters

Follow the same process as I have described here.

 

Step #5. Activate both filters

The last step is to activate both filters. Go to Admin (in GA) > Data Filters and set both triggers (Internal traffic and developer traffic) to active. You can do that by opening each filter, changing its Filter state, and then save the changes.

 

Then test everything once again.

 

3) Cookie-Based Exclusion

Cookie-based exclusion involves setting cookies for internal users and utilizing them to filter out internal traffic in GA4. This method requires users to access a designated URL or perform a specific action to set the exclusion cookie. While cookies offer granularity in targeting internal traffic, they may pose challenges, such as cookie expiration and user privacy considerations.

 

Step 1. Set a cookie for internal users

However, keep in mind that just like any other method mentioned in this article, this one has its flaws. If most of your employees are using Safari (or browsing with iOS), the Intelligent Tracking Prevention will limit the lifetime of a cookie, and your employees will have to revisit that unique link often.

 

Let’s say that your website’s URL is www.mybusiness.com. Then you can tell your employees to visit the following URL: www.mybusiness.com?internal_user=true

 

Then go to Google Tag Manager and create a Custom HTML tag, paste the following code inside of it:

 

<script>

 

 var cookieName = “gtm_internal_user”; // Name of your cookie

 var cookieValue = “internal”; // Value of your cookie

 var expirationTime = 31104000; // One year in seconds

 expirationTime = expirationTime * 1000; // Converts expirationtime to milliseconds

 var date = new Date(); 

 var dateTimeNow = date.getTime(); 

 

 date.setTime(dateTimeNow + expirationTime); // Sets expiration time (Time now + one month)

 var date = date.toUTCString(); // Converts milliseconds to UTC time string

 document.cookie = cookieName+”=”+cookieValue+”; SameSite=None; Secure; expires=”+date+”; path=/; domain=.” + location.hostname.replace(/^www\./i, “”); // Sets cookie for all subdomains

 

</script>

 

Set this tag to fire on a Pageview trigger when Page URL contains internal_user=true.

 

Step 2. Cookie variable

Go to GTM > Variables > 1st Party Cookie and enter the following settings:

Save the variable

 

Step 3. Create a developer filter in GA4

Create a developer filter in GA4, just as explained in method#1.

 

Step 4. Create a lookup table in GTM to override the traffic_type parameter

Go to Variables > New > Lookup table and enter the following settings:

Here we are using the Debug Mode variable as input. If the GTM preview mode is enabled, this variable will return true. Therefore, the lookup table variable will return the word “developer”.

 

If GTM Preview mode is not being used, the Debug Mode variable will return false. Therefore, we will return the value of the 1st Party Cookie Variable that you created in the first step. If the cookie exists, then its value will be sent to GA. If the cookie does not exist, then it will be as undefined (meaning that GA4 will not send the traffic_type key at all).

 

Save the variable.

 

Finally, go to your Google tag and enter the following parameter: traffic_type. And its value should be the lookup table you’ve just created.

Step 4. Test the filters

Follow the same process as I have described here.

 

Step 5. Activate both filters

The last step is to activate both filters. Go to Admin (in GA) > Data Filters and set both triggers (Internal traffic and developer traffic) to active. You can do that by opening each filter, changing its Filter state, and then saving the changes.

 

Then test everything once again.

Conclusion

 

Excluding internal traffic in GA4 is crucial for ensuring the accuracy and reliability of analytics data. By implementing appropriate filtering methods, businesses can mitigate the impact of internal interactions on their analytics reports. Whether through IP address filtering, data layer parameters, or cookie-based exclusion, organizations can maintain the integrity of their analytics insights and make informed decisions based on reliable data.

FAQs

 

  • Why is excluding internal traffic important in Google Analytics 4?
    RExcluding internal traffic helps prevent internal interactions from distorting analytics data, ensuring the accuracy of reports and insights.

  • Can IP address filtering exclude all internal traffic effectively?

    While IP address filtering can be effective, it may not capture internal traffic from remote or dynamic IP addresses. Supplementing with other methods, such as data layer parameters, may offer greater precision.

  • How often should internal traffic filters be reviewed and updated?

    It’s advisable to review and update internal traffic filters periodically, especially if there are changes in the organization’s network infrastructure or remote work arrangements.

  • Are there any privacy considerations associated with cookie-based exclusion?

    Yes, businesses must ensure compliance with privacy regulations and obtain user consent where necessary when implementing cookie-based exclusion methods.

About Author

Aarav is an accomplished professional specializing in digital analytics and data visualization. With a robust background in artificial intelligence projects, Aarav has consistently demonstrated a commitment to excellence. His expertise lies in harnessing data for insightful decision-making, and he excels in crafting compelling visualizations that effectively communicate complex information. Aarav's strategic approach and passion for innovation position him as a valuable asset at the forefront of digital analytics.

Share This Article:
Facebook
Twitter
LinkedIn
Email
Table of content

Related Stories

Unlock the potential of your data with GA4's Data Layer Push, empowering seamless integration of custom...
Channel Groups in GA4: Never Ask Again" empowers marketers with precise insights by categorizing traffic sources....
In Google Analytics 4 (GA4), duplicate transactions can occur when multiple identical transaction events are recorded...
"Discover the keys to effortless integration: Our comprehensive guide walks you through every step of importing...