Skip to content

Migrate react-ga to react-ga4 (Universal Analytics is deprecated) #1595

Description

@shmowen

Problem

client/package.json depends on react-ga v3.3.1, the client library for Google's legacy Universal Analytics (UA-XXXXXXX-X tracking IDs). Google fully shut off standard Universal Analytics data processing in July 2023.

Any Google Analytics property created or migrated since then only issues GA4 Measurement IDs (G-XXXXXXXXXX), which react-ga cannot use. ReactGA.initialize(TRACKING_ID) (called in client/src/index.js and client/src/App.js) will silently no-op or error with a GA4 ID, meaning analytics reporting is effectively non-functional regardless of what value is configured in the VITE_GA_TRACKING_ID env var / GA_TRACKING GitHub secret.

Fix

Migrate from react-ga to react-ga4 (or load the gtag.js snippet directly), updating the two call sites:

  • client/src/index.js
  • client/src/App.js

Context

Found while auditing PR #1389 (dev container / Vite migration). Separately, the GA_TRACKING GitHub secret needs updating from the old REACT_APP_GA_TRACKING_ID=... naming to VITE_GA_TRACKING_ID=... (Vite only exposes VITE_-prefixed env vars) — but that rename alone won't restore working analytics without this library migration too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    dependenciesPull requests that update a dependency file

    Projects

    Status
    Todo/Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions