X
Do you want actionable Internet Marketing advice delivered right to your inbox?
Sign up for our Newsletter

The TechWyse ‘Rise To The Top’ Blog!

Experts from TechWyse and around the world offer how-to's, strategy advice, interviews, infographics and insights to help your SEO and internet marketing campaigns Rise To The Top!

How To Implement Subdomain And Cross Domain Tracking In Universal Analytics

Search Engine Optimization August 13th, 2015

By

Subdomain And Cross Domain

Webmasters are often confused with subdomain tracking and cross domain tracking. They are required to track the correct traffic data to Google Analytics when you have multiple domains or subdomains. According to the nature of your website structure, there is a difference in the implementation.

If you have a single domain and multiple subdomains, which are treated as a single site – you need to implement subdomain tracking.

When you have multiple domains with one or more subdomains that are treated as a single site – you need to implement cross domain tracking.

Part 1 – When You Have a Single Domain With Multiple Subdomains (Subdomain Tracking)

Let’s imagine that your website, example.com, has a mobile version of the site at m.example.com (I recommend a responsive website rather than maintaining two separate sites for desktop and mobile). With no subdomain tracking implemented, the mobile site will be treated as a referral whenever any user moves to the desktop site from the mobile site.

This isn’t the best way for your sites to be tracked because both sites are meant for one purpose and the traffic from either domain should carry the same Source and Medium.

Also on TechWyse

Top 12 Content Marketing Metrics To Start Tracking Now
Tracking On and Offline Advertising Using Google Analytics

For example, if a visitor lands on your mobile website (m.example.com) through a Google search, the source would be listed as “Organic” and the medium as “Google.” When the same visitors visit your main website (example.com) through a link in the mobile website, the source and medium must remain as Organic and Google.

However, if you have not implemented subdomain tracking in Google Analytics, the visit to the main website will be tracked as “Referral” source with the mobile site as the medium.on the mobile

To avoid this and allow you to analyze the correct date, it’s important to add subdomain tracking in Analytics.

1. How to Track Subdomain Traffic Through Universal Analytics

Important to note: You don’t need to make any changes to the tracking script.  Earlier when classic Google Analytics is used, the subdomain tracking was done by tweaking the analytics tracking script. However, for universal analytics, there is no need of tweaking the code.

To begin, update the “Referral Exclusion List” by going to Admin -> Property -> Tracking Info -> Referral Exclusion List.
Referral Exclusion List

Important to note: You don’t need to add subdomains to the referral exclusion list since the Analytics automatically identifies the subdomains associated with the main domain. For example, you will only need to add ‘example.com’ to the referral exclusion list to exclude traffic from m.example.com, test1.example.com, test2.example.com, and so forth.

2. Append the Full URLs in Analytics

Using a single view would make it difficult to identify the hostname since Google Analytics displays the URLs without the domain name. This means that when sites are listed, for example, both test.example.com/123 & example.com/123 will be displayed as “/123.”  This can be confusing to identify which hostname the link is from.

There is a quick solution to allow you to view the domain name. You can do so by adding a filter to the view.

Go to Filters – > Add New Filter -> Custom -> Advanced

Select “Hostname” for Field A and enter (.*) as the field value.

Select “Request URL” for Field B and enter (.*) as the field value.

Select “Request URL” for Field C and enter $A1$B1 as the field value.

Then, leave the check boxes in its default setting.

Filter Information

3. How to Track Your Sites Separately

Sometimes, you want to be able to track you main website, mobile website, and subdomains separately in Analytics.

You can do so by creating Two Views, one for your main domain and the other for your subdomains.

For example, I am adding “Main Domain View” and “Mobile Domain View” for the main site and mobile site, respectively.

Mobile Domain View

Then, apply a filter to “Main Domain View”
Filters – > Add New Filter -> Custom -> Include -> Hostname
The filter pattern is (www.|^)example.com.

 

Cross Domain Tracking in Google Analytics

Apply a similar filter to “Mobile Domain View”
Filters – > Add New Filter -> Custom -> Include -> Hostname
The filter pattern is m\.example\.com.

 

Tracking the Mobile Traffic in Google Analytics

That’s it! Now, you can see the main domain traffic data in the view “Main Domain View”, subdomain traffic data in “Mobile Domain View” and the combined (main domain + subdomain) traffic data in “All Website Data” .

Part 2 – When You Have Multiple Domains With One or More Subdomains That Are Treated as a Single Site (Cross Domain Tracking)

Here, let’s say you have two domains, example1.com and example2.com, and two subdomains, sub1.example1.com and sub2.example2.com. If you treat all these domains as one site and want to track the traffic to all these sites combined, without changing the Source and Medium, you need to implement cross domain tracking.

1. First, you need to add all the main domains to the “Referral Exclusion List.”

Important to note: You do not need to add subdomains to the referral exclusion list, as the Analytics automatically identifies the subdomains associated with the main domain. For example, you will only need to add example1.com and example2.com to the referral exclusion list to exclude traffic from sub1.example1.com and sub2.example2.com.

2. Append the Full URLs in Analytics

See the implementation process in Part 1.

3. Cross Domain Linking

Since Google Analytics place unique cookies to each site, when the visitor moves from example1.com to example2.com, the visit will be tracked as a new session.

To avoid creating a session and to keep both visits as a single session, we need to pass the same cookie value to the second domain.

This is possible by implementing the “autoLink Plugin” in Google Analytics. By tweaking the tracking script, we can load this plugin and pass the cookie values across sites.

You can do so by editing and updating your tracking code with the coding below:

<script>

 (function(i,s,o,g,r,a,m){i[‘GoogleAnalyticsObject’]=r;i[r]=i[r]||function(){
 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
 })(window,document,’script’,’//www.google-analytics.com/analytics.js’,’ga’);

 ga(‘create’, ‘UA-XXXXXX-X’, ‘auto’, {
‘allowLinker’: true
});
ga(‘send’, ‘pageview’);

ga(‘require’, ‘linker’);
ga(‘linker:autoLink’, [example1.com, example2.com], false, true);
</script>

Important to note: Make sure to edit the UA number and domain names while implementing the code in your site!

Voila! You have successfully done cross domain tracking. Make sure to check the results through “Real-Time” option in Google Analytics.

Post By Sreelal G Pillai (11 Posts)

Connect

avatar
Sreelal's expertise in SEO, Web Analytics and Conversion Optimization has helped a number of clients to successfully promote their business online.

Post a Comment

Send me SEO tips!

2 Comments

Archives

2017
x

Like us on Facebook

TechWyse Internet Marketing

How To Implement Subdomain And Cross Domain Tracking In Universal Analytics

Read time: 5 minutes