Skip to content

Fix/analytics #463

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 2 commits into from
Aug 27, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
update level/step complete analytics
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
ShMcK committed Aug 27, 2020
commit cccca84125911a6ad00c378d9663b75961b8f523
6 changes: 3 additions & 3 deletions src/actions/onTutorialConfigNew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 22 additions & 7 deletions src/services/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
Expand Down Expand Up @@ -50,21 +51,35 @@ export const onReset = async (actions: TT.StepActions): Promise<void> => {

// run when an uncaught exception is thrown
export const onError = async (error: Error): Promise<void> => {
telemetryOnError(error)
telemetry.onError(error)
}

// run when a step task passes
export const onStepComplete = async ({ levelId, stepId }: { levelId: string; stepId: string }): Promise<void> => {
export const onStepComplete = async ({
tutorialId,
levelId,
stepId,
}: {
tutorialId: string
levelId: string
stepId: string
}): Promise<void> => {
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<void> => {
logger(`ON LEVEL COMPLETE: ${JSON.stringify(levelId)}`)
export const onLevelComplete = async ({
tutorialId,
levelId,
}: {
tutorialId: string
levelId: string
}): Promise<void> => {
telemetry.onEvent('level_complete', { tutorialId, levelId, version: VERSION })
}

// run when all levels are complete
export const onTutorialComplete = async ({ tutorialId }: { tutorialId: string }): Promise<void> => {
logger(`ON TUTORIAL COMPLETE: ${JSON.stringify(tutorialId)}`)
telemetry.onEvent('tutorial_complete', { tutorialId, version: VERSION })
}
12 changes: 7 additions & 5 deletions src/services/telemetry/index.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 => {
Expand All @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion web-app/src/services/state/actions/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand All @@ -146,6 +147,7 @@ export default (editorSend: any) => ({
editorSend({
type: 'EDITOR_LEVEL_COMPLETE',
payload: {
tutorialId: context.tutorial?.id || '',
levelId: context.position.levelId,
},
})
Expand All @@ -154,7 +156,7 @@ export default (editorSend: any) => ({
editorSend({
type: 'EDITOR_TUTORIAL_COMPLETE',
payload: {
tutorialId: context.tutorial?.id,
tutorialId: context.tutorial?.id || '',
},
})
},
Expand Down