Measure activity across multiple domains

This article is for developers who need to measure multiple domains with the same Google tag. This article focuses on a gtag.js code implementation. You can also configure additional domains in your Google tag settings of your GA4 property.

Cross-domain measurement enables two or more related sites on separate domains to be measured as one. Google tags provide a common way for supported products to measure activity when your customer journeys span across multiple domains. Cross-domain measurement works for all Google products, including Google Analytics, Google Ads conversion measurement, and Floodlight conversions.

When to implement cross-domain measurement

Implement cross-domain measurement when you need to combine data for two or more domains.

Suppose you have a website at example-petstore.com, and your website's ecommerce component is hosted by a third-party shopping cart on another domain: example-commerce-host.com/example-petstore.

Without cross-domain measurement, a user who arrives to your online store and then proceeds to your third-party shopping cart is counted as two separate users, with two separate sessions of different durations. With cross-domain measurement, activity is captured as a single user.

How it works

The domain linker shares first-party measurement cookies between a source domain and a destination domain. The first-party measurement cookies are stored in a web browser, and can only be accessed by pages on the same domain.

Setup for cross-domain measurement is a two-step process:

  1. The source domain decorates URLs that point to the destination domain so that they contain the first-party measurement cookie values of the source domain.
  2. The destination domain checks for the presence of linked measurement cookies.

Cross-domain measurement with Google tags will add a linker parameter to URLs that point to the destination domain. The linker parameter is identified in URL query parameters with the key _gl:

https://www.example.com/?_gl=1~abcde5~

On the destination domain, tags are configured to check for linker parameters in the URL. If a valid linker parameter is found, the tag extracts the first-party measurement cookie and stores it.

Set up cross-domain linking

To set up cross-domain measurement on the source domain for URLs that point to the destination domain, you need to create a linker object. The linker will listen for clicks on links that point to destination domains, and it will automatically add a linker parameter to the URLs of those links.

The linker object requires a domains parameter, which is an array of one or more domains. This code will append the linker parameter to links on a page that points to a target domain 'example.com':

gtag.js

To set up cross-domain measurement for the Google tag, add a linker command to your tag as follows. Replace example.com with your domain.

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

  gtag('config', 'TAG_ID');
</script>

You can list multiple string values in the domains property. When the domains property has at least one value, gtag.js will accept incoming domain links by default. You can add several values to the domains propety and use the same code snippet on every domain.

Google Analytics 4 honors gtag('set', 'linker', ...) configurations, so long as the linker command is set before the relevant config command. However, we recommend configuring cross-domain measurement on the Admin page of Google Analytics 4. Learn how to set up cross domain measurement

gtag('set', 'linker', {
  'domains': ['example.com', 'example-b.com']
});

Tag Manager

For Google Ads and Floodlight tags

In Tag Manager, create a Conversion Linker tag and then set the tag to auto-link domains.

  1. Click Tags > New.
  2. Click Tag Configuration and select Conversion Linker.
  3. Select a trigger. In most cases, you should use a trigger that fires on all page views for cross domain measurement, or on specific conversion pages where site visitors will land after an ad is clicked.
  4. Select Enable linking across domains. This setting will enable this tag to handle incoming links that have a linker parameter.
  5. In Auto Link Domains, enter a list of domains that should be linked with this tag. Any links that point to a domain listed in this field will have a linker parameter appended to the URL.
  6. Save and publish your tag configuration.

Learn more about Tag Manager's Conversion Linker

For Google Analytics 4 tags

In Google Analytics 4, cross-domain measurement is configured via the Google Analytics Admin interface. Learn how to set up cross domain measurement with Google Analytics 4.

For legacy Universal Analytics tags

To configure a legacy Universal Analytics tag in Tag Manager to measure user interaction across multiple domains:

  1. In Tag Manager, open your Google Analytics Settings variable or Universal Analytics tag for editing.
    • To find your Google Analytics Settings variable, click Variables and then click the appropriate variable in the list.
    • To find your Universal Analytics tag, click Tags and then select the appropriate tag in the list.
  2. Navigate to More Settings > Cross Domain Tracking.
  1. In the Auto Link Domains field, enter a comma-separated list of domains.
  2. To receive incoming links from other domains, navigate to More Settings > Fields to Set and add a field with a Field Name of allowLinker and a Value of true.
  3. Save your changes and publish the container.

Linker parameter reference

Parameter Type Accepted values
accept_incoming boolean true (default if domains has value), false
decorate_forms boolean true, false (default)
domains array An array of one or more domains, e.g. ['example1.com', 'example2.com']
url_position string 'query' (default), 'fragment'

accept_incoming

Once a user arrives at a page on the destination domain with a linker parameter in the URL, your tags need to be configured to parse that parameter.

If the destination domain has been configured to automatically link domains, it will accept linker parameters by default. No additional code is required on the destination domain.

If the destination domain is not configured to automatically link domains, you can instruct the destination page to look for linker parameters. Set the accept_incoming property to true.

gtag.js

gtag('set', 'linker', {
  'accept_incoming': true
});

Tag Manager

Conversion Linker tags for Google Ads and Floodlight conversions

Activate the Accept incoming linker parameters checkbox.

Universal Analytics tags

accept_incoming is automatically set when you add values to the Auto Link Domains field found in Google Analytics Settings Variables or in Universal Analytics tags under More Settings > Cross Domain Tracking.

decorate_forms

To measure form data that is sent between multiple domains, set the decorate_forms property to true.

gtag.js

gtag('set', 'linker', {
  'domains': ['example.com'],
  'decorate_forms': true
});

Tag Manager

Conversion Linker tags for Google Ads and Floodlight conversions

Set Decorate Forms to true.

Google Analytics 4 tags and Universal Analytics tags

There is no control for decorate_forms for Google Analytics tags in Tag Manager. Refer to the gtag.js guidance instead.

domains

An array of one or more domains to be linked.

gtag.js

gtag('set', 'linker', {
  'domains': [
    'example1.com',
    'example2.com',
    'subdomain1.example3.com',
    'subdomain2.example3.com'
  ]
});

Tag Manager

Conversion Linker tags for Google Ads and Floodlight conversions

  1. Select Enable linking across domains
  2. In the Auto Link Domains field, enter a list of domains separated by commas.

Google Analytics 4

Set up cross domain measurement via the Admin pages in Google Analytics.

Universal Analytics tags

accept_incoming is automatically set when you add values to the Auto Link Domains field found in Google Analytics Settings Variables or in Universal Analytics tags under More Settings > Cross Domain Tracking.

url_position

Certain content applications require you to use a fragment/hash character (#) as the delimiter in URL strings instead of the more commonly used question mark character (?) to indicate query parameters. To configure the linker parameter to appear in the URL after a # character (e.g. https://example.com#_gl=1~abcde5~), set url_position to fragment.

gtag.js

gtag('set', 'linker', {
  'domains': ['example.com'],
  'decorate_forms': true,
  'url_position': 'fragment'
});

Tag Manager

Conversion Linker tags for Google Ads and Floodlight conversions

If you need to tell Tag Manager to read the unique parameter from a fragment (#) instead of a standard query (?), set URL Position to Fragment. Otherwise, leave this option set to the default Query Parameter option.