Tracking Multiple Properties And Aggregating Data in Google Analytics

By Posted in - Google Analytics on November 24th, 2015 0 Comments

Tracking multiple domains/subdomains and aggregating the data from all sources can be a tricky thing to tackle. I did some research and found a way to use Google Analytics to solve this issue.

The Problem

You have multiple domains to track, but you also want to be able to view the data from all domains in one area. One option is to create multiple filters, which could make your life a bit difficult. Another option is to create multiple properties in Google Analytics and have your website send data to multiple properties in one go.

Many of the solutions I came across described how to do this. However, I found it quite annoying with regard to things such as event tracking. My code basically looked like this:

That doesn’t look pretty at all and seems like a waste of time if you’re going to be tracking multiple things in multiple areas. Ideally, I’d want to have one piece of code that triggers this for multiple properties at the same time.

The Solution

Initially, you will need to setup the multiple Google Analytics properties. For this example, we will be using UA-XXX-1 and UA-XXX-2 for the two properties.

Instead of the code you would normally insert at the head of your code from GA, you will update it slightly to use the following:

One of the main things you will notice is the addition of “{‘name’: ‘Collection’}” on lines 9 and 10. Each property needs to have its own name to make it unique, so it can be called specifically. For instance, on line 10, we call that specific object to send a page view via “Collection.send” instead of the normal “send”.

Note: You can name it whatever you want!

This code basically sends a page view to your subdomain/subproperty and also a page view to your main domain/aggregated data property. The ideal way would be that the first code is always the subdomain/subproperty, and the second bit of code would be the main/aggregated data property. This way, you can copy and paste your code in the other sites and just update the first property’s ID.

For the next part, we want to have our GA triggers get sent to both properties without making our code look really ugly. A clean and simple solution was provided by Philip Walton over at Stack Overflow:

Then all you would need to do is the following:

Optional Step

If you would like to have the domain names show up in reports for the aggregated data, do the following steps in the main/aggregate data property. Note that this is optional

  • Admin > Filters > Add Filter
  • Filter Type: Custom filter > Advanced
  • Field A: Hostname Extract A: (.*)
  • Field B: Request URI Extract: (.*)
  • Output To: Request URI Constructor: $A1$B1


Questions? Comment below or reach out to us on twitter @MediaCause.