Skip to content

Add GA4 tag to head

Javier Garcia requested to merge 922-ga4-gtag-gitlab-com into master

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

https://youtu.be/q4A5LOSV7pc

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

  1. Set GITLAB_SIMULATE_SAAS=1 in your environment to make GDK act as SaaS, since this change only affects SaaS.
  2. 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.
  3. In gitlab.yml, add a your GTM ID in the extra block for both the google_tag_manager_id and google_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'
  4. Start or restart your GDK
  5. bundle exec rails c to open the Rails console and enable some feature flags:
  6. Turn on Feature.enable(:gitlab_gtm_datalayer)
  7. Open the Google Tag Assistant
  8. Visit http://localhost:3000/users/sign_up from the Tag Assistant
  9. In the Left menu, check Consent and look for something like this Screen_Shot_2022-07-13_at_11.29.39_AM
  10. You can also skip the tag assistant and visit localhost:3000/users/sign_up and run window.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.

Edited by Javier Garcia

Merge request reports

Loading