How to Set Up Cross-Domain Tracking

Andy

Last Update 3 jaar geleden

Cross-Domain Tracking


Cross-domain tracking makes it possible for Google Analytics to see sessions on two related sites (such as an eCommerce site and a separate shopping cart site) as a single session. This is sometimes called site linking.


To set up cross domain tracking, you'll need to be comfortable editing HTML and coding in JavaScript, or have help from an experienced web developer with these skills.


Cross-Domain Tracking Overview


To track sessions, Google Analytics (GA) collects a customer ID value for every visit. Customer ID values are stored in cookies. Cookies are stored on a per-domain basis, and websites on one domain cannot access cookies set for another domain. When tracking sessions across multiple domains, the customer ID value has to be transferred from one domain to the other. To do this, the GA tracking code has linking features that allow the source domain to place the customer ID in the URL parameters of a link, where the destination domain can access it.


Cross-Domain Tracking - Modifying the Tracking Code


To set up cross-domain tracking for multiple top-level domains, you need to modify the Google Analytics tracking code on each and every domain. You should have a basic knowledge of HTML and JavaScript or work with a developer to set up cross-domain tracking. The examples in this article uses the Universal Analytics tracking code snippet (analytics.js).


Google Analytics Account Property - Primary Domain


For cross-domain tracking, set up one property in your GA account. Use the same tracking code snippet and tracking ID from that property for all of your domains.


You need to edit the tracking code snippet for cross domain tracking to work. If you haven’t already included the snippet on all your web pages, you might want to copy and paste it into a text editor before continuing with the instructions here. This way, you only have to make the changes once before including the modified snippet on all your web pages.


  • Edit the tracking code for the primary domain.
  • Find the 'create' line in the snippet. For a website called example-1.com, it looks like this:
  • Make the following changes to the snippet:
  • Remember to replace the example tracking ID (UA-XXXXXX-Y) with your own domain's tracking ID, and replace the example secondary domain (example-2.com) with your own secondary domain name (e.g. yourdomain.my39shop.com.com).


The tracking code snippet must contain these changes every place it appears on your primary domain.


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:

The tracking code snippet on your primary domain should look like this:

Tracking Code on Secondary Domains


Again, find the 'create' line in the code snippet. Make the following changes:    

Remember to replace the example tracking ID (UA-XXXXXX-Y) with your own tracking ID, and replace the example primary domain (example-1.com) with your own primary domain name.


The tracking code snippet must contain these changes every place it appears on your secondary domain.


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:

The tracking code snippet on your primary domain should look like this:

Reporting Views and Adding Filters


By default, Google Analytics only includes the page path and page name, not the domain's name. For example, you might see your pages appear in the Site Content report like this:


  • about/contactUs.html
  • about/contactUs.html
  • products/buy.html


Because the domain names aren’t listed, it might be hard to tell which domain each page belongs to.


To get the domain names to appear in your reports you need to do two things:


  1. Create a copy of your reporting view that includes data from all your domains in it.
  2. Add an advanced filter to that new view. The filter will tell Google Analytics to display domain names in your reports.


Follow this example to set up a view filter that displays domain names in your reports when you have cross-domain tracking set up. For some fields, you need to select an item from the drop-down menu. For others, you need to input the characters here:


Filter Type: Custom filter > Advanced


  • Field A: Hostname Extract A: (.*)
  • Field B: Request URI Extract: (.*)
  • Output To: Request URI Constructor: $A1$B1


Click Save to create the filter.


You can validate that filters are working as expected using Google Tag Assistant Recordings. Tag Assistant Recordings can show you exactly how your filters change your traffic.


Add Domains to the Referral Exclusion List


When a user's journey crosses from your first domain on to your second domain, it appears to GA that the user was referred to your second domain from your first domain and a new session is created. If you want to be able to track a single session across multiple domains to add your domains to the referral exclusion list.


Check that Cross-Domain Tracking Works


The best way to validate that cross-domain tracking is set up correctly is to use Google Tag Assistant Recordings. When you make a session that crosses domains, it can tell you instantly whether it worked or not.

If you have any questions, feel free to reach us out at [email protected]

Was this article helpful?

0 out of 0 liked this article

Still need help? Message Us