The domain linker functionality enables two or more related sites on separate domains to be measured as one. The gtag.js framework provides a common way for supported Google products to measure activity when your customer journeys span across multiple domains.
The domain linker shares 1st party measurement cookies between a source domain and a destination domain. The 1st 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:
- The source domain decorates URLs that point to the destination domain so that they contain the 1st party measurement cookie values of the source domain.
- The destination domain checks for the presence of linked measurement cookies.
Cross-domain measurement with gtag.js adds 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, gtag.js is configured to check for linker parameters in the URL. If a valid linker parameter is found, gtag.js extracts the 1st party measurement cookie and stores it.
Basic setup
To set up cross-domain measurement on the source domain for URLs that point to the destination domain, use the set
command 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':
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_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_MEASUREMENT_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. This allows you to use the same code snippet on every domain.
gtag('set', 'linker', {
'domains': ['example.com', 'example-b.com']
});
decorate_forms
If you have forms on your site that point to the destination domain, set the decorate_forms
property to true
.
gtag('set', 'linker', {
'domains': ['example.com'],
'decorate_forms': true
});
url_position
To configure the linker parameter to appear in the URL after a fragment (#
) instead of as a query parameter (?
) (e.g. https://example.com#_gl=1~abcde5~
), set the url_position
parameter to fragment
.
gtag('set', 'linker', {
'domains': ['example.com'],
'decorate_forms': true,
'url_position': 'fragment'
});
accept_incoming
Once a user arrives at a page on the destination domain with a linker parameter in the URL, gtag.js needs 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('set', 'linker', {
'accept_incoming': true
});
Parameters table
Parameter | Type | Accepted values |
---|---|---|
'accept_incoming' |
boolean | true (default if domains has value), false |
'domains' |
array | An array of one or more domains, e.g. ['example1.com', 'example2.com'] |
'decorate_forms' |
boolean | true , false (default) |
'url_position' |
string | 'query' (default), 'fragment' |