Skip to content

Migrate to Google Analytics 4 (GA4) #2181

@chalin

Description

@chalin

This is part of a CNCF-wide effort to upgrade project websites to GA4 since Google has deprecated Universal Analytics (UA). For more details, see:

Tasks: stage 1 (no code changes are necessary)

  • Create a GA4 site tag under the CNCF projects account.
    The new GA4 stream measurement ID is: G-80ZM8LGB96
  • Connect to the GA4 site tag from the UA tag.

Tasks: stage 1b - upgrade to use gtag.js

  • Upgrade website to use gtag.js library - Switch to use of gtag.js library for analytics #2207
  • Use GA4 setup assistant to "reconnect" the two tags. Can't use the GA4 setup assistant to connect site tags from different accounts it would seem.
  • Confirm that the GA4 site tag is receiving events
  • Confirm that the UA site tag, UA-58468480-1, is still receiving events

Tasks: stages 2 & 3

  • Connect UA ID from GA4 site tag
  • Configure GA4 ID through Netlify snippet injection, "Google Analytics 4 - only in production", just before </head>:
    {% if CONTEXT == 'production' %}
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-80ZM8LGB96"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
    
      gtag('config', 'G-80ZM8LGB96');
    </script>
    {% endif %}
  • Disconnect to the GA4 site tag from the UA tag
  • Confirm that the GA4 site tag is receiving events and that the UA site tag, UA-58468480-1, is still receiving events:
    image

Related

More:

/cc @nate-double-u @caniszczyk


Current website analytics info:

  • UA site tags:
    • UA-58468480-1, main and actively used tag.
    • UA-58468480-2: a tag planned for use over a separately deployed blog, but it seems that it never used in production AFAICT, only during test deploys from 2015-2016 (GA screenshot to be added shortly).
    • UA-58468480-3 is the tag actively used for promcon.io

Hugo layout relevant for the main tag:

  • <!-- Google Analytics -->
    <script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
    ga('create', 'UA-58468480-1', 'auto');
    ga('send', 'pageview');
    </script>

Previous issue on this topic: #2175.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions