Set up Cross domain

Set up cross-domain measurement

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

Cross-domain measurement overview

To measure sessions, Analytics collects a Client-ID value in 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.

Edit the code on your restaurant website

Select the script you are using on your site.

Set up cross-domain measurement using gtag.js

To set up automatic cross-domain measurement on restaurant domain for URLs pointing to DinnerBooking, configure the domains property of the linker parameter in your property’s config.

When configured and running, gtag.js will listen for selections on links that point to DinnerBooking, and it will automatically add the linker parameter to those links immediately prior to navigation starting. (Waiting until a user clicks a link to add the linker parameter is necessary because linker parameters expire after two minutes.)

If you have forms on your site pointing to the destination domain, set the optional decorate_forms property of the linker parameter to true.

For example, this code will append the linker parameter to any links on the page that point to the target domain ‘dinnerbooking.com’:

gtag(‘config’, ‘GA_MEASUREMENT_ID’, {
‘linker’: {
‘domains’: [‘dinnerbooking.com’]
}
});

Set up cross-domain measurement using analytics.js

Find the create line in the Analytics script. For a website called restaurant.com, it looks like this: 

ga(‘create’, ‘UA-XXXXXXX-Y’, ‘restaurant.com’);

Make the following changes to the snippet (the changes you need to make are in bold red text):  

ga(‘create’, ‘UA-XXXXXXX-Y’, ‘auto’, {‘allowLinker’: true});
ga(‘require’, ‘linker’);
ga(‘linker:autoLink’, [‘dinnerbooking.com’]);

Remember to replace the example Google Analytics ID (UA-XXXXXX-Y) with your own ID.

Set up cross-domain measurement using Google Tag Manager

If you use Google Tag Manager, follow the instructions in Google Tag Manager instead.

Further reading:
https://developers.google.com/analytics/devguides/collection/gtagjs/cross-domain (gtag.js)

https://support.google.com/analytics/answer/1034342?hl=en (analytics.js)