-
Notifications
You must be signed in to change notification settings - Fork 259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Analytics] Track install and error events #1984
base: trunk
Are you sure you want to change the base?
Changes from 4 commits
acea593
4592b34
1fa774d
ad63c49
a10dfc9
beeb585
4bc154e
718155a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,69 @@ | ||
import { StepDefinition } from '@wp-playground/blueprints'; | ||
import { logger } from '@php-wasm/logger'; | ||
|
||
/** | ||
* Declare the global window.gtag function | ||
*/ | ||
declare global { | ||
interface Window { gtag: any; } | ||
interface Window { | ||
gtag: any; | ||
} | ||
} | ||
|
||
/** | ||
* Google Analytics event names | ||
*/ | ||
type GAEvent = 'load' | 'step'; | ||
type GAEvent = 'load' | 'step' | 'install' | 'error'; | ||
|
||
/** | ||
* Log a tracking event to Google Analytics | ||
* @param GAEvent The event name | ||
* @param Object Event data | ||
*/ | ||
export const logTrackingEvent = (event: GAEvent, data?: {[key: string]: string}) => { | ||
if (typeof window === 'undefined' || !window.gtag) { | ||
return; | ||
} | ||
window.gtag('event', event, data); | ||
} | ||
export const logTrackingEvent = ( | ||
event: GAEvent, | ||
data?: { [key: string]: string } | ||
) => { | ||
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); | ||
} | ||
}; | ||
|
||
/** | ||
* Log Blueprint step events | ||
* @param step The Blueprint step | ||
*/ | ||
export const logBlueprintStepEvent = (step: StepDefinition) => { | ||
/** | ||
* Log the names of provided Blueprint's steps. | ||
* Only the names (e.g. "runPhp" or "login") are logged. Step options like | ||
* code, password, URLs are never sent anywhere. | ||
*/ | ||
logTrackingEvent('step', { step: step.step }); | ||
|
||
if (step.step === 'installPlugin' && (step as any).pluginData.slug) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this account for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both. It will run whenever a step is completed. |
||
logTrackingEvent('install', { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the advantage of having a single There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. None, it will probably be easier to build reports with separate events. |
||
plugin: (step as any).pluginData.slug, | ||
}); | ||
} else if (step.step === 'installTheme' && (step as any).themeData.slug) { | ||
logTrackingEvent('install', { | ||
theme: (step as any).themeData.slug, | ||
}); | ||
} | ||
}; | ||
|
||
/** | ||
* Log error events | ||
* | ||
* @param error The error | ||
*/ | ||
export const logErrorEvent = (source: string) => { | ||
logTrackingEvent('error', { | ||
source, | ||
}); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While testing this I realized that request errors show only a white screen without any error messages.
I think that we can improve this, so I opened an issue #1993
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to also log errors when the
source
is empty?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From reading the code this shouldn't happen, but let's track it to make sure it stays like that. a10dfc9