Top
Guide to setting up Google Analytics URL filters
Blue gradient overlay

Guide to setting up Google Analytics URL filters

Many websites have multiple domain names, including testing and development versions of websites. To avoid traffic to those websites skewing your live website’s Google Analytics data, it’s a good idea to add a filter in analytics. This also prevents fake data from being sent to your analytics account by external sites, e.g. for Google Analytics Referrer Spam. You can add these filters alongside existing filters, e.g. to exclude your internal staff network traffic, etc.

Here’s how to set up the filters. But first a few important points about how GA filters work:

  1. You should always have one unfiltered view, even if that’s not the one you work from normally
  2. Any traffic filtered out on a view cannot be brought back in later - i.e. the filtering is permanent
  3. When a filter is applied to GA, it only affects data collected after that point
  4. Filters take up to 24 hours to take effect
  5. If you have multiple views, be aware that filters can be applied to more than one view and any edits or deletions will affect all of those views. If you need unique changes for a single view, create a new filter

More information can be read on Google’s help article here.

Step 1 - find out which domain names are sending GA data at the moment

In GA, go to a basic report, like the Behaviour > Site Content > All Content report. Make sure your date range at the top is set to a suitably long period - e.g. 1 year of data or more.

Change the primary dimension to Hostname and show the results in a pie chart:

Image removed.

Then look through the results. Make sure you show more than 10 rows if necessary. You will see all of the domain names that have sent data to this Google Analytics view for that time period. Decide which of them should be kept for the “live only” view. Often this will be a single domain name, but if you track multiple domains and haven’t already filtered them into separate views, you may see other organisation domains or subdomains, e.g. both www.example.com and shop.example.com.

Step 2 - create a new view

It may be preferable to create a new view rather than changing filters on an existing view. But both are options if everybody who uses the existing view is happy with that.

There should always be at least one view that doesn’t have any filters applied as a backup even if it’s not used day-to-day.

If you are making a brand new view then check the settings such as site search, bot filtering, Goals, Content Grouping, E-Commerce, and Access settings - these might need to be copied from an existing view.

OK, now, on either a new view or existing view if agreed follow these steps.

Filter for a single live website domain

  1. Go to Admin (bottom left) > select the correct view > Filters.
  2. Check that there are no filters already set up for the same issue - if not proceed
  3. Create a new filter. The typical settings for a website with only one live domain name will be:
  4. Filter type = Predefined
  5. Include only > traffic to the hostname > that are equal to
  6. Hostname = www.example.com where you enter the exact live domain name, including www or other subdomains only if that is used
  7. Before saving the filter, make sure that you click “Verify this filter”
  8. This will show you how the filter affects traffic - like a preview. Make sure that the change shown in the preview matches your expectations before saving. Do not save if you are unsure.

Image removed.


Filter for multiple live website domains

If you are adding a filter for more than one domain name, you will need to configure the new filter differently. You can provide multiple domains, separated by the pipe character '|'. You would add that like this example, where we are setting a filter to include 3 domains - www.example.com, shop.example.com and crm.example.com:

  1. Create a new filter
  2. Filter type = Custom
  3. Filter Field = Hostname
  4. Filter pattern = www\.example\.com|shop\.example\.com|crm\.example\.com
  5. Note you must use backslashes before any dots as shown in step 3
  6. Verify the filter and make sure you are happy with the results before saving

Image removed.

Step 3 - check back in

It’s important to check back 24 hours and 48 hours later to make sure the filter is working as expected. You’ll want to see that the filter is working and that the data you see on reports is as expected. Click around several reports and compare them with reports on the backup unfiltered view.