Repository navigation
Add analytics of user behaviour #96
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7a8ff6c
Add analytics on download behaviour
david-mears-2 4727a41
Don't track user if they have opted out of tracking
david-mears-2 4c4b1f3
Add missing e2e test for location downloads
david-mears-2 762b698
Track usage of log scale toggle using Posthog analytics
david-mears-2 847365b
Track plot controls usage with Posthog
david-mears-2 d1d34d9
Move download analytics from components to shared util
david-mears-2 6a5be7c
Apply debounce to all relevant tracking functions
david-mears-2 3d44638
Update src/components/PrivacyModal.vue
david-mears-2 95ef0ea
Lint
david-mears-2 4856717
Make boolean analytics properties have explicit/understandable values…
david-mears-2 ad55151
Rename event props for which posthog insists on outdated types
david-mears-2 4b80b25
Merge branch 'main' into analytics-on-downloads
david-mears-2 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import { computed, watch, type Ref } from 'vue'; | ||
| import { | ||
| trackLogScaleToggle, | ||
| trackPlotControls, | ||
| type PlotAnalyticsProperties, | ||
| } from '@/utils/analytics'; | ||
| import { BurdenMetric, Dimension } from '@/types'; | ||
|
|
||
| export default ({ | ||
| focuses, | ||
| exploreBy, | ||
| splitByActivityType, | ||
| legendSelections, | ||
| burdenMetric, | ||
| rowDimension, | ||
| columnDimension, | ||
| withinBandDimension, | ||
| logScaleEnabled, | ||
| }: { | ||
| focuses: Ref<string[]>, | ||
| exploreBy: Ref<Dimension.LOCATION | Dimension.DISEASE>, | ||
| splitByActivityType: Ref<boolean>, | ||
| legendSelections: Ref<Record<string, string[]>>, | ||
| burdenMetric: Ref<BurdenMetric>, | ||
| rowDimension: Ref<Dimension>, | ||
| columnDimension: Ref<Dimension | null>, | ||
| withinBandDimension: Ref<Dimension>, | ||
| logScaleEnabled: Ref<boolean>, | ||
| }) => { | ||
| const plotAnalyticsProperties = computed((): Omit<PlotAnalyticsProperties, 'logOrLinearScale'> => ({ | ||
| focuses: [...focuses.value], | ||
| exploreBy: exploreBy.value, | ||
| activityTypeSplit: splitByActivityType.value ? 'split' : 'unsplit', | ||
| legendSelections: [...(legendSelections.value[exploreBy.value] ?? [])], | ||
| burdenMetric: burdenMetric.value, | ||
| rowDimension: rowDimension.value, | ||
| columnDimension: columnDimension.value, | ||
| withinBandDimension: withinBandDimension.value, | ||
| })); | ||
|
|
||
| // This does not fire on initial app load, only on user-initiated changes to plot controls. | ||
| watch([plotAnalyticsProperties, logScaleEnabled], ([plotProperties, logScaleEnabledValue]) => { | ||
| trackPlotControls({ | ||
| ...plotProperties, | ||
| logOrLinearScale: logScaleEnabledValue ? 'log' : 'linear', | ||
| }); | ||
| }); | ||
|
|
||
| watch(logScaleEnabled, (enabled) => { | ||
| trackLogScaleToggle(enabled ? 'log' : 'linear', { | ||
| ...plotAnalyticsProperties.value, | ||
| }); | ||
| }); | ||
| }; |
This file contains hidden or 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,5 +1,6 @@ | ||
| import posthog from "posthog-js"; | ||
| import { locationURL } from "./externalURLs"; | ||
| import { debounce } from 'perfect-debounce'; | ||
|
|
||
| const analyticsDisabledKey: Readonly<string> = "analyticsDisabled"; | ||
|
|
||
|
|
@@ -64,3 +65,49 @@ export const initialisePosthog = () => { | |
| } | ||
| }); | ||
| }; | ||
|
|
||
| export const trackDownload = ( | ||
| downloadType: "summary_table_by_location" | "summary_table_by_filename", | ||
| additionalProperties: Record<string, string | Array<string>>, | ||
| ) => { | ||
| if (!analyticsPermittedInitially) return; | ||
| posthog.capture('download', { | ||
| download_type: downloadType, | ||
| ...additionalProperties, | ||
| }); | ||
|
david-mears-2 marked this conversation as resolved.
|
||
| }; | ||
|
|
||
| export type PlotAnalyticsProperties = { | ||
| focuses: string[], | ||
| exploreBy: string, | ||
| activityTypeSplit: 'split' | 'unsplit', | ||
| legendSelections?: string[], | ||
| burdenMetric: string, | ||
| rowDimension: string, | ||
| columnDimension: string | null, | ||
| withinBandDimension: string, | ||
| logOrLinearScale: 'log' | 'linear', | ||
| }; | ||
|
|
||
| // Only capture changes to plot controls if they are stable for 8 seconds. | ||
| // This is in order to see which combinations of plot controls are most of interest, | ||
| // avoiding transient states as users navigate to their desired state. | ||
| const debounceDuration = 8000; | ||
|
|
||
| export const trackLogScaleToggle = debounce(( | ||
| newScale: "log" | "linear", | ||
| plotProperties: Omit<PlotAnalyticsProperties, 'logOrLinearScale'>, | ||
| ) => { | ||
| if (!analyticsPermittedInitially) return; | ||
| posthog.capture('log_scale_toggle', { | ||
| newScale, | ||
| ...plotProperties, | ||
| }); | ||
|
Comment on lines
+101
to
+105
Contributor
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. Should this be delayed to ensure stability too?
Contributor
Author
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. It's only fair. |
||
| }, debounceDuration); | ||
|
|
||
| export const trackPlotControls = debounce((plotProperties: PlotAnalyticsProperties) => { | ||
| if (!analyticsPermittedInitially) return; | ||
| posthog.capture('plot_controls_change', { | ||
| ...plotProperties, | ||
| }); | ||
| }, debounceDuration); | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.