Reputation: 445
I want to convert my current Google Analytics tracking code to use the newer gtag.js (Global Site Tag) What syntax is needed replace the below values with values that will work with the newer Global Site Tag?
My current code:
ga('create', 'UA-XXXXXXXX-1', 'auto', {'allowLinker': true});
ga('require', 'linker');
ga('linker:autoLink', ['subdomain.example.com'] );
What would I convert the above to, to make it work with the below?
Revised gtag code:
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXX-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
// what to add here?
gtag('config', 'UA-XXXXXXXXX-1');
</script>
I looked through documentation, but don't have access to Google Tag Manager which seems like it may help with this, but hoping there is a way to just add the necessary code snippets?
Upvotes: 1
Views: 1481
Reputation: 8907
You should be able to find more information here https://developers.google.com/analytics/devguides/collection/gtagjs/cross-domain, but to answer your question, it looks like you should have:
gtag('config', 'UA-XXXXXXXXX-1', {
'linker': {
'domains': ['subdomain.example.com']
}
});
Upvotes: 1