[UA] Cross domain measurement with gtag.js [Legacy]

You are viewing a legacy article about Universal Analytics. Learn more about Google Analytics 4 replacing Universal Analytics.

Cross-domain measurement makes it possible for 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 measurement, you'll need to be comfortable editing HTML and coding in JavaScript, or have help from an experienced web developer.

Learn more about setting up your basic Google Analytics tag.

In this article:

Cross-domain measurement overview

To analyze sessions, Google Analytics collects a Client-ID value with every hit. Client-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 you measure sessions across multiple domains, the Client-ID value has to be transferred from one domain to the other. To do this, the Analytics code has linking features that allow the source domain to place the Client-ID in the URL parameters of a link, where the destination domain can access it.

Set up cross-domain measurement

To set up cross-domain measurement, refer to the gtag.js developer documentation.

Set up reporting views and add filters

By default, Analytics only includes the page path and page name, not the domains 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: Create a copy of your reporting view that includes data from all your domains in it and add an advanced filter to that new view. The filter will tell 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 measurement set up. For some fields, you need to select an item from the dropdown 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 you expect 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 journey crosses from your first domain to your second domain, Analytics interprets that as the user having been referred by your first domain to your second domain, and Analytics creates a new session. If you want to be able to measure a single session across multiple domains, you need to add your domains to the referral exclusion list.

Check that cross-domain measurement Works

The best way to validate that cross-domain measurement 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.

Here’s an example Tag Assistant Recordings report that shows what it looks like when cross-domain measurement is not setup properly.

Related resources

Was this helpful?

How can we improve it?
true
Choose your own learning path

Check out google.com/analytics/learn, a new resource to help you get the most out of Google Analytics 4. The new website includes videos, articles, and guided flows, and provides links to the Google Analytics Discord, Blog, YouTube channel, and GitHub repository.

Start learning today!

Search
Clear search
Close search
Google apps
Main menu
4073823733894547395
true
Search Help Center
true
true
true
true
true
69256
true
false