Tips for Cross-Domain Tracking in Google Analytics

By Megalytic Staff - July 23, 2014

As data-driven professionals, we want to use actionable data to guide the marketing decisions we make every day. We understand that making decisions based on insight, not gut feeling, helps us better align our sites with the needs and wants of our customers.
However, this is only true when the data used to guide these decisions has been collected correctly. Acting on faulty data can be worse than acting on no data at all, as it allows us to make assumptions about user activity and website performance that are not true.
While Google Analytics provides a fairly simple setup process for basic sites, there are a number of backend settings that need to be tweaked to properly track more complex setups. One of the most common problems encountered in Google Analytics is not properly tracking across different domains or subdomains.

cross domain tracking people

For example, let’s say your site is example.com. You decide to set up a blog and to host that blog on a subdomain. Let’s say that subdomain is blog.example.com.

Subdomain Tracking

If you don’t make any changes in Google Analytics and continue to use the same code, you will be unable to distinguish which pages were on example.com and which ones were on blog.example.com when reviewing reports. Think of the homepage, which generally shows as a single forward slash (/) in your reports. If you haven’t tweaked any settings, the top-level pages of both example.com and blog.example.com will both be listed as the same page in your reports.

The example below shows stats for a site with both English and Spanish subdomains (example.com and es.example.com). As you can see, if you look at the homepage overall, you see an average time on site of 2:20. But when you segment by language to look at English vs. Spanish speakers to approximate views to each version of the page, you see Spanish users spent significantly less time on the page. Of course, without taking the time to segment this data, you would never see this difference in analytics when just looking at the default All Pages report.

comparing domains in google analytics

As you can see, you want to ensure Google Analytics is set up to properly show data from all sites when you are tracking multiple domains. You’ll want to think about two stages: making sure, first of all, that each domain or subdomain is actually feeding data into analytics, and next, that the data you’re getting is accurate.

First, you’ll want to make sure the data from each site is actually going into your analytics account, which can be checked by looking at the “Real Time” analytics view while navigating to each subdomain or separate domain you’d like to track. You’ll need to ensure you have the proper code on your site. While tracking separate subdomains once required extra tweaks in the tracking code placed on the site, Universal Analytics covers this by default. If you haven’t yet upgraded to Universal Analytics , we strongly encourage you to take the plunge.

However, tracking different top-level domains still requires some code adjustments.

Tracking Multiple Top-Level Domains

First, let’s talk about the tracking code changes necessary to track separate top-level domains.

Why would you want to link separate top-level domains in the same Google Analytics property in the first place? Perhaps you sell products through a third-party ecommerce site and aren’t able to host the store on your own domain. In that case, you’ve chosen to install the same Google Analytics code across both domains to allow you to track all the way from the first customer touchpoint to the moment they purchased.

You’ll want to edit the tracking code you have installed in your site ( note: these instructions assume you’re using Universal Analytics ). Look for this line in the code, with example-1.com being your domain:

ga('create', 'UA-XXXXXXX-Y', 'example-1.com');

Then, edit this line of code to look like the below example, with edits in red, and example-2.com being the second domain you’d like to link to:

ga('create', 'UA-XXXXXXX-Y', 'auto', {'allowLinker': true} );
ga('require', 'linker');
ga('linker:autoLink', ['example-2.com'] );

If you are linking three or more domains, you’ll want to make sure to list any additional ones in the final line of code, as in the following example.

ga('linker:autoLink', ['example-2.com' , 'example-3.com'] );

Finally, go to the second site and look again for the create line in the code. Edit this site to link back to the original, as follows. Again, include any other domains involved in the final line.

ga('create', 'UA-XXXXXXX-Y', 'auto', {'allowLinker': true} );
ga('require', 'linker');
ga('linker:autoLink', ['example-1.com'] );

For more details, see Google Analytics’ page on this topic .

Keeping Data Clean

Setting up the tracking code properly is a crucial first step. But, whether you’re tracking subdomains or different top level domains, you’ll also want to ensure you can associate data with the proper domains when you see it in the Google Analytics interface. As in the homepage example earlier, if any pages have the same path, they’ll show as the same page in analytics. For example, blog.example.com and example.com would both show as the forward slash (/), and blog.example.com/about and example.com/about would both show as /about.

If you don’t have pages with the same path, you may decide you can still keep track of which ones are on which domain. However, if you want to determine which pageviews occurred on which domain or subdomain, there are a couple of approaches you can take.

First, you can filter your view to show the domain in page reports. See these instructions to add the domain name to your reports. You’ll then be able to easily filter which visits came to example-1.com and which came to example-2.com and even look at page flow between the domains.

Second, you can create separate views for each subdomain. For example, say you’ve hosted a blog at blog.example.com off from your main site. You would then create a separate profile and call it “Blog”.

Within the Blog view, set up a filter to include only views of the subdomain you want.

google analytics view to include blog domain

Next, within a second view for the main site, set up a filter that excludes the blog from showing up.

google analytics view to exclude blog

You’ll then see pageviews for the respective sites easily accessible in separate views. The image below shows the two views we just set up, one for the main domain excluding the blog, and another strictly for the blog subdomain. You can access this list by navigating to Home from the top navigation in Google Analytics, then clicking on the specific account and property to drill down to a list of views.

see all views in google analytics

Note: View filters, like the ones described here apply to hits rather than sessions . So, if a visitor lands on a blog page and then visits your main site, the Blog Excluded view will show only the Pageviews from this session that do not include blog pages, as users may potentially go back and forth between your blog and main site during the course of a session. For example, in the Main Site view, the Landing Page for sessions that came from the blog will show up as (not set), since the Blog Excluded view doesn’t have a record of where the session started.

Monitoring for Discrepancies

Finally, once you have set up your account to properly track different domains, keep an eye on the data to ensure you are not encountering any problems. Watch to make sure filters are truly set up to accurately show the domain info you want in each view, especially keeping an eye on page reports. As Google Analytics does not allow you to apply any changes retroactively, any faulty setup issues will skew the data permanently.

You can check to see if domains are being handled correctly using secondary dimensions in the All Pages report (Behavior > Site Content > All Pages). Click on “Secondary dimension and select Hostname.

select hostname as secondary dimension in google analytics

Now, use the Advanced Filter to select a page that exists in both domains – such as the homepage “/”. If your filters are working correctly, you should only see one domain in the Hostname column. If there is a problem with the setup, you might see multiple hostnames showing up. Below, you can see that there was a problem with our filtering setup for the support.megalytic.com, and we have pageviews for both homepages showing up in this view. Luckily, we corrected that relatively quickly, and there is only one pageview from the support domain.

usindg a filter to see single page multiple domains in google analytics

Conclusions

Making sure you’re getting the right data in your Google Analytics account is a necessary step in ensuring that your business can properly track the results you’re getting from your site. If you’re planning on using separate domains or subdomains, be sure to make the necessary edits to your tracking code and analytics views to be able to get the data you need.