Blog» Google Analytics: how to filter by multiple domains and paths in a view

Google Analytics: how to filter by multiple domains and paths in a view

By Peter Keung  | May 24, 2017  |  Business solutions

You want to be able to track visitor analytics for websites that spread across multiple subdomains and domains in the same Google Analytics property, tracking users across sites in unified sessions. Let's suppose you have a general-purpose publication with a travel section spread across multiple subdomains and domains, as well as across different paths. You can create a view in Google Analytics so that the team in charge of the travel section can focus on the data they're interested in, with statistics and reports for the travel pages only.

For this example, let's presume your travel section lives at www.mugo.ca/travel-blog, travel.mugo.ca, and mugobooking.ca.

In order to filter by multiple domains and paths, first make sure you've set up cross-domain tracking if you're tracking across domains (not just subdomains). Then, create a view in Google Analytics and add the following filters in this order:

Add hostname to URL

By default, the hostname is not part of Google Analytics reports, and cannot be filtered on. However, you can extract the hostname and add it to another field. In this case, we'll prepend it to the request URI field. This will be useful not just for reports, but so that we can add a subsequent filter that is able to look at both the hostname and the path.

Use the "Custom" filter type, then select the "Advanced" option. Then fill in the fields as follows:

  • In "Field A -> Extract A", select "Hostname" and enter (.*).
  • In "Field B -> Extract B", select "Request URI" and enter (.*).
  • In "Output To -> Constructor", select "Request URI" and enter $A1$B1 to essentially concatenate the hostname and path into the "Request URI" field.
  • Mark the checkboxes for "Field A Required" and "Override Output Field".
GA Filter: Add hostname to URL

Lowercase URLs

This is technically optional, but will ensure that your reports group the URL path statistics if some users visit /Travel-Blog while others visit /travel-blog. For this filter, select the "Custom" filter type, then select the "Lowercase" option and apply it to the "Request URI" filter field.

GA Filter: Lowercase URLs

Travel domains and paths

For this filter, select the "Custom" filter type, then select the "Include" option and apply it to the "Request URI" filter field. For the filter pattern, enter www.mugo.ca/travel-blog|travel.mugo.ca|mugobooking.ca. It's important to enter all of your URL filtering into a single filter, because Google Analytics "include" filters are applied on top of each other. In other words, if you created separate filters for www.mugo.ca/travel-blogtravel.mugo.ca, and mugobooking.ca, for each page view Google Analytics would look at the URL and see whether it matches every filter. Of course, a single URL cannot match both www.mugo.ca/travel-blog and travel.mugo.ca.

GA Filter: Travel domains and paths

With the above 3 filters in place, you should now have a view that filters on multiple domains and paths. Repeat the process for additional views if needed!


Related Blog Posts

Tracking individual users in Google Analytics

Google Analytics is the most popular tool for understanding how people are finding and using your site. In addition to its standard reports, you can use...

Read more »

Comments

blog comments powered by Disqus

Hi, we're Mugo Web - Nice to meet you!

We're a group of web experts who solve complex web problems.

Learn more about us »

Search


Categories


Yes - we can do that.

Many years of experience with complex websites allows us to offer total solutions.

Learn more about what we can do »

We love our clients (and they love us too)

We've solved problems across North America and around the world.

Learn more about what we've done »

We tweet too

Follow us on Twitter for the latest Mugo happenings

mugo twitter page @mugo

© 2008 - 2017 Mugo Web. All rights reserved.