-
Notifications
You must be signed in to change notification settings - Fork 274
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
Open
bgrgicak
wants to merge
14
commits into
trunk
Choose a base branch
from
add/error-and-install-logs-to-ga
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
acea593
Track install and error events
bgrgicak 4592b34
Don't track URLs and try sending event
bgrgicak 1fa774d
Rename boot to bootSiteClient
bgrgicak ad63c49
Don't send error if source is unknown
bgrgicak a10dfc9
Track errors with unknown source
bgrgicak beeb585
Track theme and plugin installs as separate events
bgrgicak 4bc154e
Remove unnecessary nullish operator
bgrgicak 718155a
Merge branch 'trunk' into add/error-and-install-logs-to-ga
bgrgicak b6084d1
Merge branch 'trunk' into add/error-and-install-logs-to-ga
bgrgicak 165153d
Merge branch 'trunk' into add/error-and-install-logs-to-ga
bgrgicak 0d4d24f
Merge branch 'trunk' into add/error-and-install-logs-to-ga
bgrgicak 996db94
Log all steps not just completed steps
bgrgicak f628f6c
Ensure plugin shorthand installs are also logged
bgrgicak b88d3b9
Add functions for theme and plugin events
bgrgicak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,12 @@ import { | |
removeClientInfo, | ||
updateClientInfo, | ||
} from './slice-clients'; | ||
import { logTrackingEvent } from '../../tracking'; | ||
import { Blueprint, StepDefinition } from '@wp-playground/blueprints'; | ||
import { | ||
logBlueprintStepEvent, | ||
logErrorEvent, | ||
logTrackingEvent, | ||
} from '../../tracking'; | ||
import { Blueprint } from '@wp-playground/blueprints'; | ||
import { logger } from '@php-wasm/logger'; | ||
import { setupPostMessageRelay } from '@php-wasm/web'; | ||
import { startPlaygroundWeb } from '@wp-playground/client'; | ||
|
@@ -100,17 +104,6 @@ export function bootSiteClient( | |
blueprint = site.metadata.runtimeConfiguration; | ||
} else { | ||
blueprint = site.metadata.originalBlueprint; | ||
// 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. | ||
const steps = (blueprint?.steps || []) | ||
?.filter( | ||
(step: any) => !!(typeof step === 'object' && step?.step) | ||
) | ||
.map((step) => (step as StepDefinition).step); | ||
for (const step of steps) { | ||
logTrackingEvent('step', { step }); | ||
} | ||
} | ||
|
||
let playground: PlaygroundClient; | ||
|
@@ -125,6 +118,9 @@ export function bootSiteClient( | |
onClientConnected: (playground) => { | ||
(window as any)['playground'] = playground; | ||
}, | ||
onBlueprintStepCompleted: (result, step) => { | ||
logBlueprintStepEvent(step); | ||
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. Actually, why only log the completed steps instead of all the steps? 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. Makes sense, I switched to logging all steps b88d3b9 |
||
}, | ||
mounts: mountDescriptor | ||
? [ | ||
{ | ||
|
@@ -177,6 +173,7 @@ export function bootSiteClient( | |
} | ||
} catch (e) { | ||
logger.error(e); | ||
logErrorEvent('boot'); | ||
bgrgicak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
dispatch(setActiveSiteError('site-boot-failed')); | ||
dispatch(setActiveModal(modalSlugs.ERROR_REPORT)); | ||
return; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,94 @@ | ||
import { StepDefinition } from '@wp-playground/blueprints'; | ||
|
||
/** | ||
* 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 } | ||
) => { | ||
if (typeof window === 'undefined' || !window.gtag) { | ||
return; | ||
} | ||
window.gtag('event', event, data); | ||
bgrgicak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
/** | ||
* 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, | ||
bgrgicak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
} | ||
}; | ||
|
||
/** | ||
* 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, | ||
}); | ||
} | ||
}; | ||
|
||
/** | ||
* 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') { | ||
logPluginInstallEvent(step); | ||
} else if (step.step === 'installTheme') { | ||
logThemeInstallEvent(step); | ||
} | ||
}; | ||
|
||
/** | ||
* Log error events | ||
* | ||
* @param error The error | ||
*/ | ||
export const logErrorEvent = (source: string) => { | ||
bgrgicak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
logTrackingEvent('error', { | ||
source, | ||
}); | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Non-rhetorical question:
It looks like this will log a generic error if
error.detail
is not defined. Do we want that?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.
This is a custom event we create, so
detail.source
should always be available, but let's be safe.I added a check for the
source
in ad63c49