SEO

A Complete Google Analytics Cross-Domain Tracking Guide 2020

Most of businesses lose important audience insights because of the lack of right data. When you have multiple website, multiple tracking codes integrated on your website. Google Analytics collects the data separately, and that is too much pain to combine the data to make the right decision for marketing.

To solve that issue, and combine the Google analytics data for your website, and sub-domains, you need to implement a right google analytics cross-domain tracking. By doing this, you can collect all the data in one place and you can easily find the insights which are helpful for your business.

Google Analytics cross-domain tracking is the process of measuring two related or different websites as one.

Image source: Google Support

Why you need Google Analytics Cross-Domain Tracking?

Example:  if you have a website semupdates.com and your blog is on blog.semupdates.com. Or you have multiple microsites or sub-domains like services.semupdates.com etc. To track the visitors coming to the site and going to the subdomain, you need to integrate google analytics cross-domain tracking.

Challenge: When a user visits your main website semupdates.com and click on the blog tab. Google Analytics tracking algorithm loses the path of that session and the session gets terminated.

The disadvantage of it would be – You will get the wrong data, which lead to the wrong decision. Your website bounce rate will increase. The content updated on the blog site won’t help you get any SEO benefits.

Solution: But if you put the google analytics cross-domain tracking in place, you will be able to get accurate data. Google Analytics will be able to track the visitors landing to your site and running through the blog section or any other section on your website or other microsites.

Google Analytics adds a string when user clicks on the sub-domain in the navigation menu bar. That string help you implement cross-domain tracking succesfully, from main site to microsite and vise versa.

google analytics cross domain tracking

How to implement google analytics cross-domain tracking for two different websites?

To implement Google Analytics cross-domain tracking successfully, you must have the knowledge of HTML & Javascript, or you would need a web developer for that.

Create a single property in your Google Analytics account. Now, you will have to use the same google analytics tracking ID on both sites which you would like to link. You have to make a few updates in your Google Analytics tracking code to implement cross-domain tracking.

  1. Go to the Analytics -> Admin -> Tracking info – > Tracking code
  2. Copy this Google analytics tracking code in the text file before making changes in the code
  3. Make a copy of that file to make the changes, so you can check the changes later.

There are two methods to do it:

  1. Google Tag Manager
  2. Manually adding code on both sites

#1 Google Tag Manager:

Google Tag Manager is a tool by Google helps you implement multiple tracking codes on the website without any code updates on the website.

  1. Create a Google Tag Manager account with the same Gmail id by which you created an Google Analytics account.
  2. Setup the container in Google Tag Manager – > Then move the main dashboard
Follow the instructions to implement cross-domain tracking through GTM:

First, go to the variables section and navigate to GA variable you have created previously on GTM for Google Analytics cross-domain tracking. Variables are created on the data layers, so once you make any changes to this, it will automatically reflect all the tags created using this variable.

Google Tag Manager - variable - GA

Enter your cookie domain which is your main domain/source domain. Then click on the ‘More Settings’ option.

Google Tag Manager 0 Variables - 3

Then you will see the ‘Cross-domain tracking’ option in the drop-down menu. Expand all the fields

Cross-domain-linking - 4

 

Fill up all the required fields under the ‘Cross-Domain Tracking’ menu. Add all the domain which you would like to link with your main domain in this field ‘Auto Link Domains’. Do not make any changes to the remaining fields.

enter linking domain - 5

Then scroll up in the ‘More Settings’ drop-down menu and follow the procedure numbered below:

  1. Click on ‘Field to set’
  2. Select the ‘allowLinker’ option from the dropdown
  3. Add ‘true’ in the ‘Value’ field
  4. Click on the ‘Save’ button at the top right corner
  5. Publish the container and you are done!

 

More Settings

Manually Adding the code on Both Sites

To manually add the code on the site, you have to extract code from your analytics account as per the given instructions in the beginning. To link both sites code manually you have to establish a linker between them.

Establish Linker between the sites

  1. By using analytics.js
  2. By using gtag.js

#2 By using analytics.js – Implement google analytics cross domain tracking

Find the create a line in the snippet. For a website called example-1.com, it looks like this:

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

Make the following changes to the snippet (the changes you need to make are in bold red text):

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

Remember to replace the example Google Analytics ID (UA-XXXXXX-Y) with your own ID, and replace the example secondary domain (example-2.com) with your own secondary domain name.

For three or more domains

Follow the example above, but add the other domains to the autoLink plugin. Even the additional comma here is important:

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

By using gtag.js

Your original gtag.js looks like this, when you copy it from your analytics account.

<!– Global site tag (gtag.js) – Google Analytics –>

<script async src=”https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-X”></script>

<script>

window.dataLayer = window.dataLayer || [];

function gtag(){dataLayer.push(arguments);}

gtag(‘js’, new Date());

gtag(‘config’, ‘UA-XXXXXXXX-X’);

</script>

On the main domain, make the following changes:

<script async src=”https://www.googletagmanager.com/gtag/js?id=GA-TRACKING_ID”></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag(‘set’, ‘linker’, {‘domains’: [‘example.com’]});
gtag(‘js’, new Date());

gtag(‘config’, ‘GA-TRACKING_ID’);
</script>OR you can can put this way:

gtag(‘config’, ‘GA_tracking_ID’, {
‘linker’: {
‘domains’: [‘example.com’]
}
});

On the sub-domain of the other site, make the following changes in gtag.js

gtag(‘config’, ‘GA_tracking_ID’, {
‘linker’: {
‘accept_incoming’: true
}
});

Bi-directional Google Analytics cross-domain tracking guide

Here is the following instruction to implement Google analytics cross domain tracking for bi-directional user flow:

On source.com, update the property’s config:

gtag(‘config’, ‘GA_tracking_ID’, {
‘linker’: {
‘domains’: [‘example-destination.com’]
}
});

On destination.com, update the property’s config:

gtag(‘config’, ‘GA_tracking_ID’, {
‘linker’: {
‘domains’: [‘example-source.com’]
}
});

Using a single snippet on all domains

On example-1.com, update the property’s config:

gtag(‘config’, ‘GA_MEASUREMENT_ID_1’, {
‘linker’: {
‘domains’: [‘example-1.com’, ‘example-2.com’]
}
});

On example-2.com, update the property’s config:

gtag(‘config’, ‘GA_MEASUREMENT_ID_2’, {
‘linker’: {
‘domains’: [‘example-1.com’, ‘example-2.com’]
}
});

Challenge:

Once you are done with code placements, Google Analytics will be able to gather data from both sites and will combine it in one view. Then the challenge would be to figure out – which domain are they visiting?

For example – In the site content report you will see:

/contact

/about-us

Domain names are not visible in these reports. So, how will you decide which domain this page belongs to?

Solution:

  1. Go to the Admin section of your analytics account
  2. Create a new view to applying various filters, so that you will have a backup view
  3. Once you created the view, then go to the advanced filter at the view level

Analytics - 7

  1. Click on the filters -> custom filtercustom-filters
  2. When you click on the ‘Custom’ filter You will see various types of filters below. Select ‘Advance’. Fill up the fields as mentioned below and Save the filter:
    1. Field A –> Extract A: Hostname = (.*)
    2. Field B –> Extract B: Request URI = (.*)
    3. Output To –> Constructor: Request URI = $A1$B1

Challenge:

When you visit sites one from another, analytics shows the data in ‘Referral traffic’ and then create a new session. So, this is not the correct way to get accurate data.

Solution:

To make these visits as a single session across multiple domains, you have to create a referral exclusion list. Follow the instructions to do that:

  1. Go to the admin section in your analytics account
  2. Click on ‘Tracking Info’ in ‘Property’ tabReferral exclusion list creation -10
  3. Click on the ‘+ ADD REFERRAL EXCLUSION’ button and enter the domain which you don’t want to see in referral traffic source section in the reporting. Then click on the ‘Create’ button.referal exclusion list - 11

To verify your Google analytics cross-domain tracking code settings you have done, please run through ‘Google Tag Assistant’ recording:

  1. Install ‘Google Tag Assistant’ chrome extension.
  2. Open your website, then click on the GTA icon in the browser. Then click on Record, and later you can view the recording it the cross-domain tracking working fine.google-teg-manager-sem

Google updates their tools, really frequently. These guides are updated as per the recent changes Google in their code and tools. Hope it will be helpful for you. If I missed something, or if you have any feedback or suggestion, please feel free to comment.

Most of the professionals follow these google analytics cross domian tracking practice in different combinations. To gather the right data is important for better marketign campaign planning and decision making. Cross-domain tracking is very crucial element in customer behaviour analysis. You need to make sure you are following the best practices for the same.

About author

Richa Pathak is Founder & Editor at SEM Updates – The Digital Marketing Magazine. She is an emerging digital marketing influencer, a creative consultant & a corporate trainer. With a decade of experience in working with B2C & B2B brands across the globe, she is also a featured author in top-10 marketing magazines globally. She offers various consulting, training, & mentorship programs to share her knowledge. Richa's principle - Plan, Execute, Learn, Implement, Repeat! Digital marketing is Richa's passion & love. She is an innovator & wants to explore more, learn more, try different tools, hacks with various campaigns. She loves reading non-fiction books and does nature photography.