From c8a6ffb6ab3ae53d1eb09ab43284a86520c76b2f Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Wed, 28 May 2025 09:33:26 -0400 Subject: [PATCH] docs(misc): fix issue with GA events during local development (#31376) This PR fixes an issue when you serve nx-dev locally and navigate between pages in the browser. You'll get an error that `gtag` is not defined since we never loaded it. We now check that we're in production environment before sending events. --- nx-dev/feature-analytics/src/lib/google-analytics.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nx-dev/feature-analytics/src/lib/google-analytics.ts b/nx-dev/feature-analytics/src/lib/google-analytics.ts index bfca9c4638..641a33f201 100644 --- a/nx-dev/feature-analytics/src/lib/google-analytics.ts +++ b/nx-dev/feature-analytics/src/lib/google-analytics.ts @@ -12,6 +12,7 @@ export function sendPageViewEvent(data: { path?: string; title?: string; }): void { + if (process.env.NODE_ENV !== 'production') return; try { gtag('config', data.gaId, { ...(!!data.path && { page_path: data.path }), @@ -29,6 +30,7 @@ export function sendCustomEvent( value?: number, customObject?: Record ): void { + if (process.env.NODE_ENV !== 'production') return; try { gtag('event', action, { event_category: category,