From 4592b34ceccab81463bbed8a258025280ebd478d Mon Sep 17 00:00:00 2001 From: Bero Date: Tue, 5 Nov 2024 06:47:36 +0100 Subject: [PATCH] Don't track URLs and try sending event --- .../playground/website/src/lib/tracking.ts | 57 ++++++------------- 1 file changed, 16 insertions(+), 41 deletions(-) diff --git a/packages/playground/website/src/lib/tracking.ts b/packages/playground/website/src/lib/tracking.ts index 1cf36f84f8..208b56eee3 100644 --- a/packages/playground/website/src/lib/tracking.ts +++ b/packages/playground/website/src/lib/tracking.ts @@ -1,4 +1,5 @@ import { StepDefinition } from '@wp-playground/blueprints'; +import { logger } from '@php-wasm/logger'; /** * Declare the global window.gtag function @@ -23,43 +24,13 @@ export const logTrackingEvent = ( event: GAEvent, data?: { [key: string]: string } ) => { - if (typeof window === 'undefined' || !window.gtag) { - return; - } - window.gtag('event', event, data); -}; - -/** - * Log Plugin install events - * @param step The Blueprint step - */ -export const logPluginInstallEvent = (step: StepDefinition) => { - const pluginData = (step as any).pluginData; - if (pluginData.slug) { - logTrackingEvent('install', { - plugin: pluginData.slug, - }); - } else if (pluginData.url) { - logTrackingEvent('install', { - plugin: pluginData.url, - }); - } -}; - -/** - * Log Theme install events - * @param step The Blueprint step - */ -export const logThemeInstallEvent = (step: StepDefinition) => { - const themeData = (step as any).themeData; - if (themeData.slug) { - logTrackingEvent('install', { - theme: themeData.slug, - }); - } else if (themeData.url) { - logTrackingEvent('install', { - theme: themeData.url, - }); + try { + if (typeof window === 'undefined' || !window.gtag) { + return; + } + window.gtag('event', event, data); + } catch (error) { + logger.warn('Failed to log tracking event', event, data, error); } }; @@ -75,10 +46,14 @@ export const logBlueprintStepEvent = (step: StepDefinition) => { */ logTrackingEvent('step', { step: step.step }); - if (step.step === 'installPlugin') { - logPluginInstallEvent(step); - } else if (step.step === 'installTheme') { - logThemeInstallEvent(step); + if (step.step === 'installPlugin' && (step as any).pluginData.slug) { + logTrackingEvent('install', { + plugin: (step as any).pluginData.slug, + }); + } else if (step.step === 'installTheme' && (step as any).themeData.slug) { + logTrackingEvent('install', { + theme: (step as any).themeData.slug, + }); } };