How to exclude a subdomain from GA4 (three ways)

PUBLISHED 11 Apr 2024 - UPDATED 12 Apr 2024

How do you exclude a subdomain from your GA4 tracking or reporting? You can remove the tracking code, use trigger exceptions in GTM, or use filters in GA4. Here I look at all three methods.

So you have Google Analytics 4 (GA4) running across your website, but there's one particular subdomain you don't want to track.

Perhaps it's a subdomain for admins only - if the site is example.com, the subdomain could be something like admin.example.com. Or perhaps your staging site is on a subdomain. Whatever the reason, you don't want any activity on that subdomain appearing in any of your GA4 reporting.

How do you go about excluding one particular subdomain? Here are three different options open to you, depending on your technical setup and level of access.

Remove the tracking code

The simplest option is to remove the tracking code entirely from the subdomain. This could be the Google tag if you installed GA4 directly, or it could be the Google Tag Manager script if you use GTM.

However, you may not have access to do this. Perhaps you're part of the marketing team, and only the development team have direct access.

Also, it could be that you use GTM for more than just GA4 (or might do in the future). In this scenario, you wouldn't want to remove GTM.

Use trigger exceptions (blocking triggers)

If your GA4 setup relies on GTM, you can use trigger exceptions to stop your GA4 tags firing on one subdomain. Trigger exceptions are sometimes known as blocking triggers, because they block tags when they are triggered. There are a few steps involved, starting with:

Enable the Page Hostname variable

To exclude a subdomain, your trigger exceptions will be based on the variable 'Page Hostname'. This is one of GTM's built-in variables, and provides the domain name (including any subdomain). But to use it, you'll first need to make sure it is enabled. Here's how:

  1. In GTM, go to Variables
  2. Alongside 'Built-In Variables', click Configure
  3. Under the Pages variables, tick Page Hostname

Selecting Page Hostname in Google Tag Manager's Configure Built-In Variables panel

  1. Click back in the main GTM panel

You'll also need to Submit (publish) this change in your workspace, but you can do that later alongside the other changes. So now let's look at creating a trigger exception.

Create the trigger exception

For the trigger exception to work, it needs the same trigger type as the tag you want to block. So if you are blocking your Google Tag, and your Google Tag fires on Initialization, your trigger exception will need to fire on Initialization as well.

Which tags to block? You'll want to block the Google Tag (especially if it sends the pageview event), but you'll also want to block your GA4 Event tags - as these will still send events to GA4 even if the Google Tag hasn't fired.

Now it's likely that your various GA4 tags will have different trigger types. Your Google Tag might fire on Initialization or Page View, but your GA4 Event tags could fire on Click: Just Links, or perhaps something like Element Visibility.

One approach is to have an individual trigger exception for each trigger type you want to block. You could have a trigger exception with the 'Initialization' trigger type that you apply to your Google Tag, and one with 'Click: Just Links' that you apply to your GA4 event tags that fire on link clicks (for example).

If you are going down this route, here's how:

  1. In GTM, go to Triggers
  2. Click New
  3. Give your new trigger a name - it's quite common to start it with 'BT' to indicate it's a blocking trigger
  4. Choose the trigger type that matches the tag you want to block
  5. Click Some Events (the exact wording here will depend on the trigger type you've chosen)
  6. Set the trigger to fire when Page Hostname equals subdomain.domain.com (put your own value, this is just an example)

Trigger configuration for blocking trigger based on Page Hostname

  1. Click Save

Just a note on the page hostname: if the subdomain you want to exclude is https://admin.example.com, the page hostname will be admin.example.com. Don't include the https://, and of course subdomains don't have www so you definitely shouldn't include that if you're blocking a subdomain.

An alternative approach is to create a trigger exception that fires on every trigger type. That way you can apply the one trigger exception to all your GA4-related tags. Here's how:

  1. In GTM, go to Triggers
  2. Click New
  3. Give your new trigger a name
  4. Choose the trigger type Custom Event
  5. Enter the event name .* (this regular expression will match all events)
  6. Tick Use regex matching
  7. Click Some Custom Events
  8. Set the trigger to fire when Page Hostname equals subdomain.domain.com

Trigger configuration for blocking trigger matching all events

  1. Click Save

Apply trigger exception to your tag

Now we'll apply the trigger exception you've just created to an existing GA4-related tag.

  1. In GTM, go to Tags
  2. Click into the tag you want to block
  3. In the Triggering section, click Add Exception
  4. Select the trigger exception you created previously - either one with the same trigger type, or one that matches all events

Google Tag tag in Google Tag Manager with trigger exception applied

  1. Click Save

Do this for all your GA4-related tag/s, then Submit (publish) your changes in GTM.

Now when a user is on your subdomain and a GA4-related tag would ordinarily fire, your trigger exception will meet its conditions and prevent that tag from firing. That means no data will be sent to your GA4 property.

Use filters in GA4

If you can't remove the code from the subdomain, and you aren't using Google Tag Manager, you may be wondering whether filters will allow you to exclude your subdomain instead.

Universal Analytics - the old version of Google Analytics - allowed you to create a custom filter which would permanently exclude traffic when a field of your choice (e.g. Hostname) matched a specified value.

Unfortunately, GA4 doesn't have this functionality: you can create a 'Data filter' (under Admin), but this only lets you permanently exclude developer traffic or internal traffic.

That said, you can apply a temporary filter to a standard report or Exploration (custom report). This doesn't stop the data being collected, but it will stop it being shown on the report itself. Effectively it hides the data.

One advantage of this approach is that it also applies to historic data (unlike a permanent filter, which only affects data going forward). Also, if you change your mind, you haven't lost any data. However it isn't suitable if there are legal or business reasons why you shouldn't be collecting data on the subdomain in the first place.

Filter out a Subdomain on a standard report

There are a couple of ways to filter out a subdomain on a standard GA4 report. You could use the 'Add filter' option under the title of the report, but this only adds a very temporary filter that gets removed as soon as you look at another report or navigate away and come back.

So instead, a better option is to 'Customise report'. This allows you to add a more persistent filter that will remain in place until you choose to remove it. Here's how.

  1. In GA4, go to your standard report (for example the Events report at Reports > Engagement > Events)
  2. Click the Customise report icon (the pencil icon below the date picker in the top right)
  3. In the 'Customise report' panel that appears, click on Add filter
  4. Click on Select dimension
  5. Start typing Hostname and click on this when it appears
  6. Choose the Match Type does not exactly match
  7. Under Value, tick your subdomain name

Build filter panel in GA4 report

  1. Click Apply
  2. Click Save (you can either save changes to the current report, or save as a new report)

One caveat when building this filter is that the match type 'does not exactly match' only lets you select from the listed hostnames, i.e. the ones that have already received traffic. So if you are setting up the filter in advance, you will need to use another match type such as 'does not contain'.

Also, note that with the GTM blocking trigger, we were making a positive match ('equals'), whereas with the GA4 filter, we're making a negative match ('does not exactly match'). That's just because of the slightly unintuitive way that blocking triggers work in GTM.

Filter out a Subdomain in an Exploration

As with a customised standard report, a filter added to a GA4 Exploration (custom report) will remain in place until you choose to remove it.

  1. In the GA4 vertical menu, click on Explore
  2. Create a new Exploration or edit an existing one
  3. Under Dimensions, click +
  4. Search for Hostname and tick it
  5. Click Import - this will allow you to use the dimension in your Exploration

  1. In the Settings column, scroll down to FILTERS
  2. Click on Drop or select dimension or metric
  3. Click on Hostname
  4. Choose the condition exactly matches
  5. Click on Enter expression then either select or type your subdomain in the format subdomain.domain.com

Hostname filter in GA4 Exploration

  1. Click Apply

So there you have it: three different ways to exclude a subdomain from your GA4 reporting. Hope this has been useful!

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
James Clark
Hi! I'm James Clark and I'm a freelance web analyst from the UK. I'm here to help with your analytics, ad operations, and SEO issues.
0
What do you think? Leave a commentx
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram