Everything you need to know about Cross domain tracking in Google Analytics

Over cross-domein tracking - Google Analytics Help
Image from support.google.com

What is cross domain tracking Google Analytics?

Cross domain tracking, also called site linking, is a process where Google Analytics is set to track activity from two separated but related websites under one umbrella. This means if that one user goes from the first site to the second one, it’s still counted as one session. This can be very useful when there are essential pages in your funnel that are hosted under a different domain. 

Normally, Google Analytics tracks any traffic within a certain URL. For example, if Google Analytics is set to track ‘convertmind.com’, it will freely track all traffic that happens within that domain. What pages users visit, how long they’re on the site, how many sessions they have, it’s all recorded. 

However, when it comes to separate URLs, Google Analytics normally treats them as a completely separate thing. Unless a user comes to your site via a referral link, Google Analytics generally doesn’t care too much about external URLs. This means that normally, your tracking is limited to one URL. Keep in mind: this goes for subdomains as well. Do you want to track both convertmind.com and blog.convertmind.com? By default, Google Analytics treats them as separate sites.

Cross-domain tracking can solve this. With cross-domain tracking, you can continue tracking users across various domains and URLs within the same session. This can give you valuable insight into how users truly behave when your funnel requires multiple domains. 

Eén dataweergave die wordt gebruikt om gegevens te verzamelen van twee aparte websites
support.google.com

For example, imagine you are running various smaller ecommerce sites, but for payment users need to go to your main site. Using cross-domain tracking, you can then continue to track them from your ecommerce site to your main site and back. All interactions will be counted as a part of one session and one user, rather than it being separated. 

With Convertmind we chose to run seperate views for blog.convertmind.com and convertmind.com.

How do I set up cross domain tracking in Google Analytics?/How do I enable cross domain tracking?

Setting up cross-domain tracking can be a little complicated. For one of the methods, some knowledge and experience regarding HTML and JavaScript is recommended. If you don’t feel you’re comfortable tinkering with your site’s code, it’s recommended to get help from an expert in web development.

You can set up cross-domain tracking two ways: via Google Tag Manager and by editing your site’s code.

Wat is Google Tag Manager? (alle mogelijkheden 2018)

Set up cross-domain tracking using Google Tag Manager

You can set up cross-domain tracking in Google Analytics with Google Tag Manager by setting up a Universal Analytics tag. You can do that by following these steps:

  1. In Google Tag Manager, go to your Google Analytics Settings variable. You can find this listed under ‘Variables’.
  2. Go to ‘More Settings’
  3. Go to ‘Cross Domain Tracking’
  4. Look for the field labeled ‘Auto Link Domains’. Enter all of the domains you want to cross track here, separated by a comma. 
  5. Now navigate to ‘More Settings’
  6. Here, go to ‘Fields to Set’
  7. Add a field and give it the Field Name ‘allowLinker’ (without quotation marks) and a Value of ‘true’ (without quotation marks). 
  8. Save your changes and publish the container

If everything’s been done correctly, cross-domain tracking should now be set up.

Track links cross-domain in Google Analytics with Google Tag Manager

Set up cross-domain tracking by modifying analytics.js

If you don’t use Google Tag Manager, you will have to modify the Analytics code on each domain you want to cross track in order to allow this.

Setting up the property in Google Analytics

Fist of all, you need to set up one property in your Google Analytics account. The same code snippet and ID from that property will be used for all of the domains you’ll be cross tracking.

Edit the code for the primary domain

Cross-tracking two domains

Open your snippet in your code editor of choice. A regular text editor like Notepad works too. 

In this example, we’ll be using example1.org as the primary domain, and we’ll be using example2.org as the domain we want to cross track with.

First, we’ll be editing the code for the primary domain. Find the create line in the snippet. The create line looks like this:

ga(‘create’, ‘UA-XXXXXXX-Y’, ‘example1.org’);

Keep in mind, UA-XXXXXXX-Y here represents your Google Analytics ID. You’ll need to make some adjustments to the code. In the code below, the adjustments are marked green. Change the code, so it looks like this:

 ga(‘create’, ‘UA-XXXXXXX-Y’, ‘auto’, {‘allowLinker’: true});

 ga(‘require’, ‘linker’);

 ga(‘linker:autoLink’, [‘example2.org’]);

Don’t forget to put your own Google Analytics ID in place of the placeholder (UA-XXXXXXX-Y). Save this as the code for your primary domain.

Next, we’ll be creating the code for the secondary page. For this, take the same basic code we started with:

ga(‘create’, ‘UA-XXXXXXX-Y’, ‘example1.org’);

Make the following adjustments:

 ga(‘create’, ‘UA-XXXXXXX-Y’, ‘auto’, {‘allowLinker’: true});

 ga(‘require’, ‘linker’);

 ga(‘linker:autoLink’, [‘example1.org’]);

Notice how we’re using the URL for the second page in the code for the first page, and the URL from the first page in the code for the second page. This is correct and how it should be done. It’s easy to get confused and mix these up though, so be wary.

Save this code as the code for the second site you’re tracking.

Once this is all done, simply implement the code on the respective sites, and you’re ready to go!

Cross-tracking three or more domains

Setting up cross-domain tracking for three or more domains isn’t much more complicated than setting up tracking for two domains.

In this example, we’ll be using example1.org as the primary domain, and we’ll be using example2.org and example3.org as the domains we want to cross track with.

First, we’ll be editing the code for the primary domain. Find the create line in the snippet. The create line looks like this:

ga(‘create’, ‘UA-XXXXXXX-Y’, ‘example1.org’);

Keep in mind, UA-XXXXXXX-Y here represents your Google Analytics ID. You’ll need to make some adjustments to the code. In the code below, the adjustments are marked green. Change the code, so it looks like this:

 ga(‘create’, ‘UA-XXXXXXX-Y’, ‘auto’, {‘allowLinker’: true});

 ga(‘require’, ‘linker’);

 ga(‘linker:autoLink’, [‘example2.org’, ‘example3.org’]);

Don’t forget to put your own Google Analytics ID in place of the placeholder (UA-XXXXXXX-Y), and to replace the example URLs with your own.. Save this as the code for your primary domain.

Next, we’ll be creating the code for the secondary page. For this, take the same basic code we started with:

ga(‘create’, ‘UA-XXXXXXX-Y’, ‘example1.org’);

Make the following adjustments:

 ga(‘create’, ‘UA-XXXXXXX-Y’, ‘auto’, {‘allowLinker’: true});

 ga(‘require’, ‘linker’);

 ga(‘linker:autoLink’, [‘example1.org’, ‘example3.org’]);

Notice how we’re using the URL for the second page in the code for the first page, and the URL from the first page in the code for the second page. This is correct and how it should be done. It’s easy to get confused and mix these up though, so be wary.

The code for page number three follows the same pattern. We start with

ga(‘create’, ‘UA-XXXXXXX-Y’, ‘example1.org’);

And we adjust it to this:

 ga(‘create’, ‘UA-XXXXXXX-Y’, ‘auto’, {‘allowLinker’: true});

 ga(‘require’, ‘linker’);

 ga(‘linker:autoLink’, [‘example1.org’, ‘example2.org’]);

With this same structure, you can add as many URLs as you want. Just make that in the code for every domain, you correctly refer to all other domains. Also make sure you structure the code correctly, with a comma and a space between every URL and apostrophes around every URL. 

Once your code is ready, simply implement your code on the respective sites, and you’re ready to go!

How do I view the domain name in my reports when I use cross-domain tracking?

Google Analytics, by default, leaves out the domain name in reports. For example, when the URL tracked is convertmind.com/beta, Google Analytics will only show ‘/beta’. For single domain tracking, this is handy because it removes a lot of clutter. However, when you’re using cross-domain tracking, you may want to know which domain the listed page is from. Thankfully, Google Analytics does allow you to do this.

To start, create a copy of your reporting view that includes data from all of your domains:

  1. On the Google Analytics main screen, go to ‘Admin’ in the navigation bar on the left
  2. Using the three dropdown menus, select the account, property and view you want to copy
  3. In the ‘View’ column on the right, select ‘View settings’
  4. Click ‘Copy view’
  5. Give this view a new name. Make sure you choose a unique name that allows you to distinguish it from the original
  6. Click ‘Copy View’

Next, create a new advanced filter for that view. This filter will instruct Google Analytics to not hide the domains from you and your reports. In order to do this, follow these steps:

  1. In the view column under the admin screen, go to ‘Filters’
  2. Click ‘+ Add Filter’
  3. Select ‘Create new filter’
  4. Give the filter a name
  5. You’ll get a choice between a Predefined and a Custom filter. Choose the Custom Filter.
  6. You’ll get six options for types of custom filters. Choose ‘Advanced’
  7. For the label ‘Field A –> Extract A’, set the ‘Select Field’ dropdown menu to Hostname. Next, in the field, enter (.*)
  8. For the label ‘Field B –> Extract B’, set the ‘Select Field’ dropdown menu to Request URI. Next, in the field, enter (.*)
  9. For the label ‘Output to –> Constructor’, set the ‘Select Field’ dropdown menu to Request URI. Next, in the field, enter $A1$B1
  10. Click ‘Save’. 

If you’ve done everything correctly, then the new view should allow you to see the domains in your reports.

How do I test cross domain tracking?

Once you’ve configured cross domain tracking properly it is time to test. All traffic from domein A to domain B should be part of the same session. So it should show in the same Source/Medium dimension.

It is our advice not to use Real Rime reports from Google Analytics to test the cross domain tracking. Real Time shows each hit only with parameters and dimensions by the hit itself. It means that you can’t view the test session in Source/medium Real Time. You’ll need to wait for the data in the standard reports.

It is easier to verify Cross Domain tracking with custom UTM parameters like this:

www.domainA.com/?utm_source=optimizer_test&utm_medium=optimizer_test&utm_campaign=optimizer_test

While stille browsing Domain A open a second page (tab) with Domain B. The Cross Domain session should be active.

in the Google Analytics View you can now apply a segment to include only your UTM traffic from above.

Cross-domain tracking test segment

Once the data hits Google Analytics, you are able to find your session when when applying your optimizer_test segment.

Turn Google Analytics into conversions

Let smart algorithms audit your Google Analytics data. Find hidden conversion leaks and increase your conversions.

Create account