Adding data layer tracking for cookie banner GCMv2 #270
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Requested by analytics team for cookie banner. This is assuming that the performance container is always loaded and only read via GTM. as per the latest google consent spec.
In the olden days, as my son would say, we used to track interactions with the cookie banner into Universal Analytics. There may still be some legacy code in the banner that was for that purpose. We never updated this to GA4 for a number of reasons, but mostly because it used the measurement API. If I recall, Mick looked into it, but I don't remember us ever really using it in GA4.
_However, using Google Consent Mode v2 offers an opportunity to track slightly differently and I'm wondering how much might be involved to send dataLayer events with the following:
only compatible with GCMv2, but it would otherwise be throwing into the dataLayer only so not a big problem
Cookie banner displays - to send AFTER performance container is loaded, only if the banner is displayed to the user
// Push the banner display event to the data layer
dataLayer.push({
'event': 'stormcb_display'
});
Accept all button click - to send when a user clicks "Accept All" button
// Push the accept all event to the data layer
dataLayer.push({
'event': 'stormcb_accept_all',
'stormcb_performance': 1,
'stormcb_thirdparty': 1
});
Reject all button click - to send when a user clicks "Reject All" (or equivalent) button
// Push the reject all to the data layer
dataLayer.push({
'event': 'stormcb_reject_all',
'stormcb_performance': 0,
'stormcb_thirdparty': 0
});
Save preferences button click - to send when a user clicks "Save" (or equivalent) after editing their cookie settings
// Push the save event to the data layer
dataLayer.push({
'event': 'stormcb_save',
'stormcb_performance': 0, // 1 if accepted, 0 if rejected
'stormcb_thirdparty': 0 // 1 if accepted, 0 if rejected
});