So in Magento2 you have GA module with javascript file:
/vendor/magento/module-google-analytics/view/frontend/web/js/google-analytics.js
part of file:
// Process page info
ga('create', config.pageTrackingData.accountId, 'auto');
if (config.pageTrackingData.isAnonymizedIpActive) {
ga('set', 'anonymizeIp', true);
}
You add here extra info required by GA in this guide: https://support.google.com/analytics/answer/1034342?hl=en
ga('create', 'UA-XXXXXXX-Y', 'auto', {'allowLinker': true});
ga('require', 'linker');
ga('linker:autoLink', ['example-2.com']);
Depending on your time and goals you can do it in few ways:
1) override this file by adding it to your Magento2 theme
vendor/[namespace]/[module_name]/Magento_GoogleAnalytics/web/js/google-analytics.js and adding required changes.
This is not usually the recommend way. However in this case looking how this JS is build it wouldn't be so bad. Just remember in case of Magento 2 update any changes to original function would need to be moved to this file.
2) using a mixin
It requires understanding how JS system works in Magento 2 (requirejs, etc). You can follow the guide here about how to use mixins: https://devdocs.magento.com/guides/v2.4/javascript-dev-guide/javascript/js_mixins.html
Proper example from guide to your case is "Extend JS function".
Using mixin is usually my default way. However sometimes depending on use case (to avoid extra js request and/or a mixin change so little or too much I decide to use first method).
3) Create a module with some configuration option in admin panel
This way if it need to be configurable.