-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
feat(stage-*): track provider card clicks and time-to-first-message #832
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 7 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
194c1ea
refactor(stage-ui,stage-web,stage-tamagotchi): migrate PostHog metada…
shinohara-rin e493f9a
refactor(stage-ui,stage-web,stage-tamagotchi): centralize build infor…
shinohara-rin f4f6743
feat(stage-ui,stage-pages): Introduce `useAnalytics` composable and t…
shinohara-rin c159447
feat(stage-ui): track time-to-first-message
shinohara-rin 0a5da0c
refactor(stage-ui): migrate analytics Pinia store from Options API to…
shinohara-rin 1e1cf93
refactor(stage-ui,stage-web,stage-tamagotchi): move PostHog logic fro…
shinohara-rin a9feae8
[autofix.ci] apply automated fixes
autofix-ci[bot] 73612e1
Update packages/stage-ui/src/stores/analytics/index.ts
shinohara-rin eedc661
refactor(stage-ui,stage-web,stage-tamagotchi): Centralize PostHog met…
shinohara-rin 59e1281
fix(stage-ui): simplify ttfm tracking
shinohara-rin 895c2dd
refactor(stage-ui): remove versionMeta
shinohara-rin 2d90e22
remove empty line
shinohara-rin 66d7af9
chore(stage-web,stage-tamagotchi): remove dead code
shinohara-rin ad87210
Merge branch 'main' into sr/analytics
nekomeowww 4e1a351
[autofix.ci] apply automated fixes
autofix-ci[bot] 23167d4
Apply suggestions from code review
nekomeowww 1c3f876
Apply suggestions from code review
nekomeowww 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,9 +2,14 @@ import type { Plugin } from 'vue' | |
| import type { RouteRecordRaw } from 'vue-router' | ||
|
|
||
| import Tres from '@tresjs/core' | ||
| import buildTime from '~build/time' | ||
|
|
||
| import { autoAnimatePlugin } from '@formkit/auto-animate/vue' | ||
| import { useAnalytics } from '@proj-airi/stage-ui/composables' | ||
| import { useSharedAnalyticsStore } from '@proj-airi/stage-ui/stores/analytics/index' | ||
| import { MotionPlugin } from '@vueuse/motion' | ||
| import { abbreviatedSha, branch } from '~build/git' | ||
| import { version } from '~build/package' | ||
| import { createPinia } from 'pinia' | ||
| import { setupLayouts } from 'virtual:generated-layouts' | ||
| import { createApp } from 'vue' | ||
|
|
@@ -38,6 +43,18 @@ import '@fontsource/sniglet' | |
|
|
||
| const pinia = createPinia() | ||
|
|
||
| // Initialize analytics | ||
| const analyticsStore = useSharedAnalyticsStore(pinia) | ||
| analyticsStore.initialize({ | ||
| version: version ?? 'dev', | ||
| commit: abbreviatedSha, | ||
| branch, | ||
| builtOn: buildTime.toISOString(), | ||
| }) | ||
|
|
||
|
Comment on lines
+45
to
+53
Member
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. We should initialize in |
||
| const { registerMetadata } = useAnalytics() | ||
| registerMetadata() | ||
|
shinohara-rin marked this conversation as resolved.
Outdated
|
||
|
|
||
| const router = createRouter({ | ||
| history: createWebHashHistory(), | ||
| // TODO: vite-plugin-vue-layouts is long deprecated, replace with another layout solution | ||
|
|
||
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,16 +1,8 @@ | ||
| import buildTime from '~build/time' | ||
| import posthog from 'posthog-js' | ||
|
|
||
| import { abbreviatedSha } from '~build/git' | ||
| import { version } from '~build/package' | ||
|
|
||
| posthog.init('phc_rljw376z5gt6vXJlc3sTr7hFbXodciY9THEQXIRnW53', { | ||
| api_host: 'https://us.i.posthog.com', | ||
| person_profiles: 'identified_only', // or 'always' to create profiles for anonymous users as well | ||
| }) | ||
|
|
||
| posthog.register({ | ||
| app_version: version ?? 'dev', | ||
| app_commit: abbreviatedSha, | ||
| app_build_time: buildTime, | ||
| }) | ||
| export default posthog |
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
16 changes: 6 additions & 10 deletions
16
apps/stage-web/src/components/Layouts/InteractiveArea/Actions/About.vue
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 |
|---|---|---|
|
|
@@ -2,10 +2,15 @@ import type { Plugin } from 'vue' | |
| import type { Router, RouteRecordRaw } from 'vue-router' | ||
|
|
||
| import Tres from '@tresjs/core' | ||
| import buildTime from '~build/time' | ||
| import NProgress from 'nprogress' | ||
|
|
||
| import { autoAnimatePlugin } from '@formkit/auto-animate/vue' | ||
| import { useAnalytics } from '@proj-airi/stage-ui/composables' | ||
| import { useSharedAnalyticsStore } from '@proj-airi/stage-ui/stores/analytics/index' | ||
|
nekomeowww marked this conversation as resolved.
Outdated
|
||
| import { MotionPlugin } from '@vueuse/motion' | ||
| import { abbreviatedSha, branch } from '~build/git' | ||
| import { version } from '~build/package' | ||
| import { createPinia } from 'pinia' | ||
| import { setupLayouts } from 'virtual:generated-layouts' | ||
| import { createApp } from 'vue' | ||
|
|
@@ -26,6 +31,19 @@ import './styles/main.css' | |
| import 'uno.css' | ||
|
|
||
| const pinia = createPinia() | ||
|
|
||
| // Initialize analytics | ||
| const analyticsStore = useSharedAnalyticsStore(pinia) | ||
| analyticsStore.initialize({ | ||
| version: version ?? 'dev', | ||
| commit: abbreviatedSha, | ||
| branch, | ||
| builtOn: buildTime.toISOString(), | ||
| }) | ||
|
|
||
|
Comment on lines
+33
to
+42
Member
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. We should initialize in |
||
| const { registerMetadata } = useAnalytics() | ||
| registerMetadata() | ||
|
shinohara-rin marked this conversation as resolved.
Outdated
|
||
|
|
||
| // TODO: vite-plugin-vue-layouts is long deprecated, replace with another layout solution | ||
| const routeRecords = setupLayouts(routes as RouteRecordRaw[]) | ||
|
|
||
|
|
||
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,16 +1,8 @@ | ||
| import buildTime from '~build/time' | ||
| import posthog from 'posthog-js' | ||
|
|
||
| import { abbreviatedSha } from '~build/git' | ||
| import { version } from '~build/package' | ||
|
|
||
| posthog.init('phc_pzjziJjrVZpa9SqnQqq0QEKvkmuCPH7GDTA6TbRTEf9', { | ||
| api_host: 'https://us.i.posthog.com', | ||
| person_profiles: 'identified_only', // or 'always' to create profiles for anonymous users as well | ||
| }) | ||
|
|
||
| posthog.register({ | ||
| app_version: version ?? 'dev', | ||
| app_commit: abbreviatedSha, | ||
| app_build_time: buildTime, | ||
| }) | ||
| export default posthog |
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
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,42 @@ | ||
| import posthog from 'posthog-js' | ||
|
|
||
| import { useSharedAnalyticsStore } from '../stores/analytics' | ||
|
|
||
| export function useAnalytics() { | ||
| const analyticsStore = useSharedAnalyticsStore() | ||
|
|
||
| function trackProviderClick(providerId: string, module: string) { | ||
| posthog.capture('provider_card_clicked', { | ||
| provider_id: providerId, | ||
| module, | ||
| }) | ||
| } | ||
|
|
||
| function trackFirstMessage(success: boolean, messageSentAt: number) { | ||
| // Only track the first message once | ||
| if (analyticsStore.firstMessageTracked) | ||
| return | ||
|
|
||
| // Calculate time from app start to message sent | ||
| const timeToFirstMessageMs = analyticsStore.appStartTime | ||
| ? messageSentAt - analyticsStore.appStartTime | ||
| : null | ||
|
|
||
| posthog.capture('first_message_sent', { | ||
| time_to_first_message_ms: timeToFirstMessageMs, | ||
| success, | ||
| }) | ||
|
|
||
| analyticsStore.markFirstMessageTracked() | ||
| } | ||
|
|
||
| function registerMetadata() { | ||
| posthog.register(analyticsStore.versionMeta) | ||
| } | ||
|
|
||
| return { | ||
| trackProviderClick, | ||
| trackFirstMessage, | ||
| registerMetadata, | ||
| } | ||
| } |
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,45 @@ | ||
| import type { AboutBuildInfo } from '../../components/scenarios/about/types' | ||
|
|
||
| import { defineStore } from 'pinia' | ||
| import { computed, ref } from 'vue' | ||
|
|
||
| export const useSharedAnalyticsStore = defineStore('shared_analytics', () => { | ||
|
nekomeowww marked this conversation as resolved.
Outdated
|
||
| const isInitialized = ref(false) | ||
| const buildInfo = ref<AboutBuildInfo>({ | ||
| version: '', | ||
| commit: '', | ||
| branch: '', | ||
| builtOn: '', | ||
| }) | ||
| const appStartTime = ref<number | null>(null) | ||
| const firstMessageTracked = ref(false) | ||
|
|
||
| const versionMeta = computed(() => ({ | ||
| app_version: buildInfo.value.version === '0.0.0' ? 'dev' : buildInfo.value.version, | ||
| app_commit: buildInfo.value.commit, | ||
| app_branch: buildInfo.value.branch, | ||
| app_build_time: buildInfo.value.builtOn, | ||
| })) | ||
|
shinohara-rin marked this conversation as resolved.
Outdated
|
||
|
|
||
| function initialize(info: AboutBuildInfo) { | ||
| if (isInitialized.value) | ||
| return | ||
|
|
||
| buildInfo.value = info | ||
| appStartTime.value = Date.now() | ||
| isInitialized.value = true | ||
| } | ||
|
|
||
| function markFirstMessageTracked() { | ||
| firstMessageTracked.value = true | ||
| } | ||
|
|
||
| return { | ||
| buildInfo, | ||
| versionMeta, | ||
|
shinohara-rin marked this conversation as resolved.
Outdated
|
||
| appStartTime, | ||
| firstMessageTracked, | ||
| initialize, | ||
| markFirstMessageTracked, | ||
| } | ||
| }) | ||
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.