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.
This commit is contained in:
parent
d74c39e9be
commit
c8a6ffb6ab
@ -12,6 +12,7 @@ export function sendPageViewEvent(data: {
|
|||||||
path?: string;
|
path?: string;
|
||||||
title?: string;
|
title?: string;
|
||||||
}): void {
|
}): void {
|
||||||
|
if (process.env.NODE_ENV !== 'production') return;
|
||||||
try {
|
try {
|
||||||
gtag('config', data.gaId, {
|
gtag('config', data.gaId, {
|
||||||
...(!!data.path && { page_path: data.path }),
|
...(!!data.path && { page_path: data.path }),
|
||||||
@ -29,6 +30,7 @@ export function sendCustomEvent(
|
|||||||
value?: number,
|
value?: number,
|
||||||
customObject?: Record<string, unknown>
|
customObject?: Record<string, unknown>
|
||||||
): void {
|
): void {
|
||||||
|
if (process.env.NODE_ENV !== 'production') return;
|
||||||
try {
|
try {
|
||||||
gtag('event', action, {
|
gtag('event', action, {
|
||||||
event_category: category,
|
event_category: category,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user