Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding data layer tracking for cookie banner GCMv2 #270

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sarah-storm
Copy link
Contributor

@sarah-storm sarah-storm commented Nov 12, 2024

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:

  • Banner displays (just an event, no other data)
  • User clicks "accept all", with two variables for performance and third party both set to 1.
  • User clicks "essential cookies only" with two variables for performance and third party both set to 0.
  • User saves consent on cookies policy page, with two variables set to 1 or 0 depending on their choice._

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
});

@sarah-storm sarah-storm requested a review from mjbp November 12, 2024 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant