igniteui-cli icon indicating copy to clipboard operation
igniteui-cli copied to clipboard

Migrate Google Analytics from UA to GA4 Measurement Protocol

Open Copilot opened this issue 4 months ago • 1 comments

Universal Analytics is deprecated as of July 1, 2023. This PR migrates to GA4 Measurement Protocol v2 to maintain analytics functionality.

Changes

GoogleAnalytics.ts

  • Endpoint: /collect/mp/collect
  • Protocol: Query string → JSON payload with client_id and events[]
  • Credentials: UA tracking ID → GA4 measurement ID + API secret (env var support)
  • Event mapping: screenviewscreen_view, eventcli_event, exceptionexception
  • Custom dimensions (cd1-cd14) mapped to GA4 event parameters

GoogleAnalyticsParameters.ts

  • Marked UA-specific fields (tid, an, ua, uid, v) as @deprecated
  • Retained for backward compatibility

GoogleAnalytic-spec.ts

  • Updated assertions for GA4 endpoint and JSON content-type
  • Fixed directory creation with recursive: true

Configuration

Set via environment variables (recommended):

IGNITEUI_CLI_GA4_MEASUREMENT_ID="G-XXXXXXXXXX"
IGNITEUI_CLI_GA4_API_SECRET="your-api-secret"

Or update defaults in GoogleAnalytics.ts (lines 29-30).

Example

Existing code works unchanged:

GoogleAnalytics.post({
  t: "screenview",
  cd: "Start",
  cd1: "angular",
  cd2: "igx-ts"
});

GA4 payload generated:

{
  "client_id": "hashed-user-id",
  "events": [{
    "name": "screen_view",
    "params": {
      "screen_name": "Start",
      "framework": "angular",
      "project_type": "igx-ts",
      "engagement_time_msec": "100"
    }
  }]
}

[!WARNING]

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.google-analytics.com
    • Triggering command: Ignite UI CLI (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Update to Google Analytics 4.0</issue_title> <issue_description>### Description
Google is deprecating the version of Google Analytics we are using now. Starting from 1st of July the analytics Ignite UI CLI is using will not work anymore.

https://support.google.com/analytics/answer/11583528 </issue_description>

Comments on the Issue (you are @copilot in this section)

  • Fixes IgniteUI/igniteui-cli#1135

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot avatar Nov 07 '25 10:11 Copilot

Coverage Status

coverage: 70.206% (-0.04%) from 70.242% when pulling 8a5657edbf428ec74608d5a313ceb7d00bf14312 on copilot/update-google-analytics-4-0 into 1f86df3d6e660b93db047415e9c53af1ef4f0a30 on master.

coveralls avatar Nov 07 '25 11:11 coveralls