Closed mpaluchowski closed 2 years ago
Do we need to change the validation on the input form to accept either prefix - or is there more to this?
Sorry - google have locked my google account, and I cannot access or test any google services.
That was my understanding, as Google's documentation isn't very clear on that, and I thought you could use the old analytics.js
code with the new tags. Alas, no. There's a new snippet required for V4 properties. I'll update the ticket description.
Can you provide the snippet?
I presume that we can use
if (starts with UA) {
use old snippet
} else {
use new snippet
}
Actually, you could replace the whole snippet with the new gtag.js
code, which supports both Universal Analytics (as long as it's working, until mid-2023), and the new v4 properties. Below GA_MEASUREMENT_ID
should be the actual property ID (UA-...
or G-...
).
<!-- Global Site Tag (gtag.js) - Google Analytics -->
<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('js', new Date());
gtag('config', 'GA_MEASUREMENT_ID');
</script>
The existing snippet has code to support additional "dimensions". In our case, we send the current tree.
Do you know how to add this in the new snippet?
I think the snippet below would be the closest. pageview
is now getting sent automatically with config
. You can add custom parameters to config
, which then apply to all pages, but in order for them to become dimensions, we need to have the extra custom_map
settings. (I made a few shortcuts below to demonstrate the mapping, while you'll probably want to use the $dimensions
variable.)
<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=<?= e($GOOGLE_ANALYTICS_ID ?? '') ?>"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '<?= e($GOOGLE_ANALYTICS_ID ?? '') ?>', {
'custom_map': {'dimension1': 'tree_name', 'dimension2': 'access_level'},
'tree_name': '<?= $tree->name() ?>',
'access_level': '<?= Auth::accessLevel($tree, $user) ?>',
});
</script>
Can we have the support for Google Analytics 4 properties? The older versions will not be supported from mid-2023, and Google is asking everyone to migrate.
G-...
. Here's the format description from Google.gtag.js
. Here's the migration guide showing the new code.