Migrate Google Analytics from UA to GA4 Measurement Protocol
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_idandevents[] - Credentials: UA tracking ID → GA4 measurement ID + API secret (env var support)
- Event mapping:
screenview→screen_view,event→cli_event,exception→exception - 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:
- Configure Actions setup steps to set up my environment, which run before the firewall is enabled
- Add the appropriate URLs or hosts to the custom allowlist in this repository's Copilot coding agent settings (admins only)
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.