diff --git a/src/actions/onTutorialConfigNew.ts b/src/actions/onTutorialConfigNew.ts index b0c83037..5c2774ac 100644 --- a/src/actions/onTutorialConfigNew.ts +++ b/src/actions/onTutorialConfigNew.ts @@ -14,9 +14,9 @@ const onTutorialConfigNew = async (action: T.Action, context: Context): Promise< const data: TT.Tutorial = action.payload.tutorial onEvent('tutorial_start', { - tutorial_id: data.id, - tutorial_version: data.version, - tutorial_title: data.summary.title, + tutorialId: data.id, + tutorialVersion: data.version, + tutorialTitle: data.summary.title, }) // validate extension version diff --git a/src/services/hooks/index.ts b/src/services/hooks/index.ts index bb37c127..ddcc7757 100644 --- a/src/services/hooks/index.ts +++ b/src/services/hooks/index.ts @@ -5,9 +5,10 @@ import { loadWatchers, resetWatchers } from './utils/watchers' import openFiles from './utils/openFiles' import runCommands from './utils/runCommands' import runVSCodeCommands from './utils/runVSCodeCommands' -import { onError as telemetryOnError } from '../telemetry' +import * as telemetry from '../telemetry' import { runTest } from '../../actions/onTest' import logger from '../logger' +import { VERSION } from '../../environment' // run at the end of when a tutorial is configured export const onInit = async (actions: TT.StepActions): Promise => { @@ -50,21 +51,35 @@ export const onReset = async (actions: TT.StepActions): Promise => { // run when an uncaught exception is thrown export const onError = async (error: Error): Promise => { - telemetryOnError(error) + telemetry.onError(error) } // run when a step task passes -export const onStepComplete = async ({ levelId, stepId }: { levelId: string; stepId: string }): Promise => { +export const onStepComplete = async ({ + tutorialId, + levelId, + stepId, +}: { + tutorialId: string + levelId: string + stepId: string +}): Promise => { git.saveCommit(`Save progress: ${stepId}`) - logger(`ON STEP COMPLETE: ${JSON.stringify({ levelId, stepId })}`) + telemetry.onEvent('step_complete', { tutorialId, stepId, levelId, version: VERSION }) } // run when a level is complete (all tasks pass or no tasks) -export const onLevelComplete = async ({ levelId }: { levelId: string }): Promise => { - logger(`ON LEVEL COMPLETE: ${JSON.stringify(levelId)}`) +export const onLevelComplete = async ({ + tutorialId, + levelId, +}: { + tutorialId: string + levelId: string +}): Promise => { + telemetry.onEvent('level_complete', { tutorialId, levelId, version: VERSION }) } // run when all levels are complete export const onTutorialComplete = async ({ tutorialId }: { tutorialId: string }): Promise => { - logger(`ON TUTORIAL COMPLETE: ${JSON.stringify(tutorialId)}`) + telemetry.onEvent('tutorial_complete', { tutorialId, version: VERSION }) } diff --git a/src/services/telemetry/index.ts b/src/services/telemetry/index.ts index 0c002312..7b5f1632 100644 --- a/src/services/telemetry/index.ts +++ b/src/services/telemetry/index.ts @@ -1,5 +1,6 @@ import TelemetryReporter from 'vscode-extension-telemetry' -import { EXTENSION_ID, VERSION, INSTRUMENTATION_KEY, NODE_ENV } from '../../environment' +import { EXTENSION_ID, VERSION, INSTRUMENTATION_KEY } from '../../environment' +import logger from '../logger' /** * Telemetry @@ -18,10 +19,9 @@ interface Measurements { let reporter: any export const activate = (subscribeFn: (reporter: any) => void): void => { - if (NODE_ENV === 'production') { - reporter = new TelemetryReporter(EXTENSION_ID, VERSION, INSTRUMENTATION_KEY) - subscribeFn(reporter) - } + logger(EXTENSION_ID, VERSION, INSTRUMENTATION_KEY) + reporter = new TelemetryReporter(EXTENSION_ID, VERSION, INSTRUMENTATION_KEY) + subscribeFn(reporter) } export const deactivate = (): void => { @@ -31,12 +31,14 @@ export const deactivate = (): void => { } export const onError = (error: Error, properties?: Properties, measurements?: Measurements): void => { + logger(error, properties, measurements) if (reporter) { reporter.sendTelemetryException(error, properties, measurements) } } export const onEvent = (eventName: string, properties?: Properties, measurements?: Measurements): void => { + logger(eventName, properties, measurements) if (reporter) { reporter.sendTelemetryEvent(eventName, properties, measurements) } diff --git a/web-app/src/services/state/actions/editor.ts b/web-app/src/services/state/actions/editor.ts index 43482bcc..a1db78b0 100644 --- a/web-app/src/services/state/actions/editor.ts +++ b/web-app/src/services/state/actions/editor.ts @@ -137,6 +137,7 @@ export default (editorSend: any) => ({ editorSend({ type: 'EDITOR_STEP_COMPLETE', payload: { + tutorialId: context.tutorial?.id || '', levelId: context.position.levelId, stepId: context.position.stepId, }, @@ -146,6 +147,7 @@ export default (editorSend: any) => ({ editorSend({ type: 'EDITOR_LEVEL_COMPLETE', payload: { + tutorialId: context.tutorial?.id || '', levelId: context.position.levelId, }, }) @@ -154,7 +156,7 @@ export default (editorSend: any) => ({ editorSend({ type: 'EDITOR_TUTORIAL_COMPLETE', payload: { - tutorialId: context.tutorial?.id, + tutorialId: context.tutorial?.id || '', }, }) }, diff --git a/web-app/src/services/state/machine.ts b/web-app/src/services/state/machine.ts index 97741258..7487f45e 100644 --- a/web-app/src/services/state/machine.ts +++ b/web-app/src/services/state/machine.ts @@ -199,11 +199,11 @@ export const createMachine = (options: any) => { }, LEVEL_COMPLETE: { target: 'LevelComplete', - actions: ['onLevelComplete'], }, }, }, LevelComplete: { + onEntry: ['onLevelComplete'], onExit: ['testClear', 'incrementLevel'], on: { NEXT_LEVEL: 'LoadNext',