Skip to content

Commit 96a04cd

Browse files
authored
Merge pull request #463 from coderoad/feature/analytics
Fix/analytics
2 parents ac33002 + b1ee1cf commit 96a04cd

File tree

5 files changed

+36
-17
lines changed

5 files changed

+36
-17
lines changed

src/actions/onTutorialConfigNew.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ const onTutorialConfigNew = async (action: T.Action, context: Context): Promise<
1414
const data: TT.Tutorial = action.payload.tutorial
1515

1616
onEvent('tutorial_start', {
17-
tutorial_id: data.id,
18-
tutorial_version: data.version,
19-
tutorial_title: data.summary.title,
17+
tutorialId: data.id,
18+
tutorialVersion: data.version,
19+
tutorialTitle: data.summary.title,
2020
})
2121

2222
// validate extension version

src/services/hooks/index.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import { loadWatchers, resetWatchers } from './utils/watchers'
55
import openFiles from './utils/openFiles'
66
import runCommands from './utils/runCommands'
77
import runVSCodeCommands from './utils/runVSCodeCommands'
8-
import { onError as telemetryOnError } from '../telemetry'
8+
import * as telemetry from '../telemetry'
99
import { runTest } from '../../actions/onTest'
1010
import logger from '../logger'
11+
import { VERSION } from '../../environment'
1112

1213
// run at the end of when a tutorial is configured
1314
export const onInit = async (actions: TT.StepActions): Promise<void> => {
@@ -50,21 +51,35 @@ export const onReset = async (actions: TT.StepActions): Promise<void> => {
5051

5152
// run when an uncaught exception is thrown
5253
export const onError = async (error: Error): Promise<void> => {
53-
telemetryOnError(error)
54+
telemetry.onError(error)
5455
}
5556

5657
// run when a step task passes
57-
export const onStepComplete = async ({ levelId, stepId }: { levelId: string; stepId: string }): Promise<void> => {
58+
export const onStepComplete = async ({
59+
tutorialId,
60+
levelId,
61+
stepId,
62+
}: {
63+
tutorialId: string
64+
levelId: string
65+
stepId: string
66+
}): Promise<void> => {
5867
git.saveCommit(`Save progress: ${stepId}`)
59-
logger(`ON STEP COMPLETE: ${JSON.stringify({ levelId, stepId })}`)
68+
telemetry.onEvent('step_complete', { tutorialId, stepId, levelId, version: VERSION })
6069
}
6170

6271
// run when a level is complete (all tasks pass or no tasks)
63-
export const onLevelComplete = async ({ levelId }: { levelId: string }): Promise<void> => {
64-
logger(`ON LEVEL COMPLETE: ${JSON.stringify(levelId)}`)
72+
export const onLevelComplete = async ({
73+
tutorialId,
74+
levelId,
75+
}: {
76+
tutorialId: string
77+
levelId: string
78+
}): Promise<void> => {
79+
telemetry.onEvent('level_complete', { tutorialId, levelId, version: VERSION })
6580
}
6681

6782
// run when all levels are complete
6883
export const onTutorialComplete = async ({ tutorialId }: { tutorialId: string }): Promise<void> => {
69-
logger(`ON TUTORIAL COMPLETE: ${JSON.stringify(tutorialId)}`)
84+
telemetry.onEvent('tutorial_complete', { tutorialId, version: VERSION })
7085
}

src/services/telemetry/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import TelemetryReporter from 'vscode-extension-telemetry'
2-
import { EXTENSION_ID, VERSION, INSTRUMENTATION_KEY, NODE_ENV } from '../../environment'
2+
import { EXTENSION_ID, VERSION, INSTRUMENTATION_KEY } from '../../environment'
3+
import logger from '../logger'
34

45
/**
56
* Telemetry
@@ -18,10 +19,9 @@ interface Measurements {
1819
let reporter: any
1920

2021
export const activate = (subscribeFn: (reporter: any) => void): void => {
21-
if (NODE_ENV === 'production') {
22-
reporter = new TelemetryReporter(EXTENSION_ID, VERSION, INSTRUMENTATION_KEY)
23-
subscribeFn(reporter)
24-
}
22+
logger(EXTENSION_ID, VERSION, INSTRUMENTATION_KEY)
23+
reporter = new TelemetryReporter(EXTENSION_ID, VERSION, INSTRUMENTATION_KEY)
24+
subscribeFn(reporter)
2525
}
2626

2727
export const deactivate = (): void => {
@@ -31,12 +31,14 @@ export const deactivate = (): void => {
3131
}
3232

3333
export const onError = (error: Error, properties?: Properties, measurements?: Measurements): void => {
34+
logger(error, properties, measurements)
3435
if (reporter) {
3536
reporter.sendTelemetryException(error, properties, measurements)
3637
}
3738
}
3839

3940
export const onEvent = (eventName: string, properties?: Properties, measurements?: Measurements): void => {
41+
logger(eventName, properties, measurements)
4042
if (reporter) {
4143
reporter.sendTelemetryEvent(eventName, properties, measurements)
4244
}

web-app/src/services/state/actions/editor.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export default (editorSend: any) => ({
137137
editorSend({
138138
type: 'EDITOR_STEP_COMPLETE',
139139
payload: {
140+
tutorialId: context.tutorial?.id || '',
140141
levelId: context.position.levelId,
141142
stepId: context.position.stepId,
142143
},
@@ -146,6 +147,7 @@ export default (editorSend: any) => ({
146147
editorSend({
147148
type: 'EDITOR_LEVEL_COMPLETE',
148149
payload: {
150+
tutorialId: context.tutorial?.id || '',
149151
levelId: context.position.levelId,
150152
},
151153
})
@@ -154,7 +156,7 @@ export default (editorSend: any) => ({
154156
editorSend({
155157
type: 'EDITOR_TUTORIAL_COMPLETE',
156158
payload: {
157-
tutorialId: context.tutorial?.id,
159+
tutorialId: context.tutorial?.id || '',
158160
},
159161
})
160162
},

web-app/src/services/state/machine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,11 @@ export const createMachine = (options: any) => {
199199
},
200200
LEVEL_COMPLETE: {
201201
target: 'LevelComplete',
202-
actions: ['onLevelComplete'],
203202
},
204203
},
205204
},
206205
LevelComplete: {
206+
onEntry: ['onLevelComplete'],
207207
onExit: ['testClear', 'incrementLevel'],
208208
on: {
209209
NEXT_LEVEL: 'LoadNext',

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy