Add GA4 tag to head
What does this MR do and why?
Describe in detail what your merge request does and why.
Closes gitlab-com/marketing/digital-experience/buyer-experience#922 (closed), which is pushing new consent
events to the dataLayer
for GitLab SaaS.
I looked at previous MRs of existing work and added the necessary script above the existing one within the same partial
Screenshots or screen recordings
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
- Set
GITLAB_SIMULATE_SAAS=1
in your environment to make GDK act as SaaS, since this change only affects SaaS. - Create a Google Tag Manager account and container ID. You should just need to follow the step 1 of the instructions. The GTM container can be empty - it just needs to exist.
- In
gitlab.yml
, add a your GTM ID in theextra
block for both thegoogle_tag_manager_id
andgoogle_tag_manager_nonce_id
values. Make sure to restart GDK (or do this step prior to starting GDK) for settings to take effect.extra: google_tag_manager_id: 'GTM-YOURIDHERE' google_tag_manager_nonce_id: 'GTM-YOURIDHERE'
- Start or restart your GDK
-
bundle exec rails c
to open the Rails console and enable some feature flags: - Turn on
Feature.enable(:gitlab_gtm_datalayer)
- Open the Google Tag Assistant
- Visit
http://localhost:3000/users/sign_up
from the Tag Assistant - In the Left menu, check Consent and look for something like this
- You can also skip the tag assistant and visit
localhost:3000/users/sign_up
and runwindow.dataLayer
in the console and you should see a value like this:
[
{
"0": "consent",
"1": "default",
"2": {
"analytics_storage": "denied",
"ad_storage": "denied",
"functionality_storage": "denied",
"region": [
"EU",
"UK",
"PE",
"RU"
],
"wait_for_update": 500
}
},
{
"0": "consent",
"1": "default",
"2": {
"analytics_storage": "granted",
"ad_storage": "granted",
"functionality_storage": "granted",
"wait_for_update": 500
}
},
{
"gtm.start": 1657736847101,
"event": "gtm.js",
"gtm.uniqueEventId": 3
},
{
"event": "gtm.dom",
"gtm.uniqueEventId": 4
},
{
"event": "gtm.load",
"gtm.uniqueEventId": 5
}
]
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Javier Garcia