Skip to content
This repository has been archived by the owner on Dec 23, 2021. It is now read-only.

Commit

Permalink
Telemetry for user input on buttons and switch (#37)
Browse files Browse the repository at this point in the history
PBI: 30429
Task: 30432

* Add telemetry for user input on simulator

* Update button handling for telemetry

* Move where telemetry event is being sent
  • Loading branch information
jonathanwangg authored Jul 10, 2019
1 parent 4e72c8a commit bceaca8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 24 deletions.
12 changes: 8 additions & 4 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,19 @@ export const CONSTANTS = {
export enum TelemetryEventName {
FAILED_TO_OPEN_SIMULATOR = "SIMULATOR.FAILED_TO_OPEN",

COMMAND_DEPLOY_DEVICE = "COMMAND.DEPLOY.DEVICE",
COMMAND_NEW_PROJECT = "COMMAND.NEW.PROJECT",
COMMAND_OPEN_SIMULATOR = "COMMAND.OPEN.SIMULATOR",
COMMAND_RUN_SIMULATOR = "COMMAND.RUN.SIMULATOR",
COMMAND_DEPLOY_DEVICE = "COMMAND.DEPLOY.DEVICE",

SIMULATOR_BUTTON_A = "SIMULATOR.BUTTON.A",
SIMULATOR_BUTTON_B = "SIMULATOR.BUTTON.B",
SIMULATOR_BUTTON_AB = "SIMULATOR.BUTTON.AB",
SIMULATOR_SWITCH = "SIMULATOR.SWITCH",

CLICK_DIALOG_DONT_SHOW = "CLICK.DIALOG.DONT.SHOW",
CLICK_DIALOG_EXAMPLE_CODE = "CLICK.DIALOG.EXAMPLE.CODE",
CLICK_DIALOG_TUTORIALS = "CLICK.DIALOG.TUTORIALS",

CLICK_DIALOG_TUTORIALS = "CLICK.DIALOG.TUTORIALS"
}

// tslint:disable-next-line: no-namespace
Expand All @@ -92,4 +96,4 @@ export namespace DialogResponses {
};
}

export default CONSTANTS;
export default CONSTANTS;
36 changes: 25 additions & 11 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as cp from "child_process";
import * as fs from "fs";
import * as open from "open";
import TelemetryAI from "./telemetry/telemetryAI";
import { CONSTANTS, DialogResponses, TelemetryEventName} from "./constants";
import { CONSTANTS, DialogResponses, TelemetryEventName } from "./constants";

let shouldShowNewProject: boolean = true;

Expand Down Expand Up @@ -34,8 +34,6 @@ export function activate(context: vscode.ExtensionContext) {
}

const openWebview = () => {
reporter.trackFeatureUsage(TelemetryEventName.COMMAND_OPEN_SIMULATOR, {});

if (currentPanel) {
currentPanel.reveal(vscode.ViewColumn.Two);
} else {
Expand Down Expand Up @@ -67,13 +65,16 @@ export function activate(context: vscode.ExtensionContext) {
// Open Simulator on the webview
const openSimulator = vscode.commands.registerCommand(
"pacifica.openSimulator",
openWebview
() => {
TelemetryAI.trackFeatureUsage(TelemetryEventName.COMMAND_OPEN_SIMULATOR);
openWebview();
}
);

const newProject = vscode.commands.registerCommand(
"pacifica.newProject",
() => {
reporter.trackFeatureUsage(TelemetryEventName.COMMAND_NEW_PROJECT, {})
TelemetryAI.trackFeatureUsage(TelemetryEventName.COMMAND_NEW_PROJECT);

const fileName = "template.py";
const filePath = __dirname + path.sep + fileName;
Expand All @@ -93,13 +94,13 @@ export function activate(context: vscode.ExtensionContext) {
.then((selection: vscode.MessageItem | undefined) => {
if (selection === DialogResponses.DONT_SHOW) {
shouldShowNewProject = false;
reporter.trackFeatureUsage(TelemetryEventName.CLICK_DIALOG_DONT_SHOW);
TelemetryAI.trackFeatureUsage(TelemetryEventName.CLICK_DIALOG_DONT_SHOW);
} else if (selection === DialogResponses.EXAMPLE_CODE) {
open(CONSTANTS.LINKS.EXAMPLE_CODE);
reporter.trackFeatureUsage(TelemetryEventName.CLICK_DIALOG_EXAMPLE_CODE);
TelemetryAI.trackFeatureUsage(TelemetryEventName.CLICK_DIALOG_EXAMPLE_CODE);
} else if (selection === DialogResponses.TUTORIALS) {
open(CONSTANTS.LINKS.TUTORIALS);
reporter.trackFeatureUsage(TelemetryEventName.CLICK_DIALOG_TUTORIALS);
TelemetryAI.trackFeatureUsage(TelemetryEventName.CLICK_DIALOG_TUTORIALS);
}
});
}
Expand Down Expand Up @@ -128,7 +129,7 @@ export function activate(context: vscode.ExtensionContext) {
return;
}

reporter.trackFeatureUsage(TelemetryEventName.COMMAND_RUN_SIMULATOR, {});
TelemetryAI.trackFeatureUsage(TelemetryEventName.COMMAND_RUN_SIMULATOR);

console.info(CONSTANTS.INFO.RUNNING_CODE);
const activeTextEditor: vscode.TextEditor | undefined =
Expand Down Expand Up @@ -231,6 +232,7 @@ export function activate(context: vscode.ExtensionContext) {
switch (message.command) {
case "button-press":
// Send input to the Python process
handleButtonPressTelemetry(message.text);
console.log("About to write");
console.log(JSON.stringify(message.text) + "\n");
childProcess.stdin.write(JSON.stringify(message.text) + "\n");
Expand All @@ -249,9 +251,9 @@ export function activate(context: vscode.ExtensionContext) {
);

// Send message to the webview
let runDevice = vscode.commands.registerCommand("pacifica.runDevice", () => {
const runDevice = vscode.commands.registerCommand("pacifica.runDevice", () => {
console.info("Sending code to device");
reporter.trackFeatureUsage(TelemetryEventName.COMMAND_DEPLOY_DEVICE);
TelemetryAI.trackFeatureUsage(TelemetryEventName.COMMAND_DEPLOY_DEVICE);

logToOutputChannel(outChannel, CONSTANTS.INFO.DEPLOY_DEVICE);

Expand Down Expand Up @@ -337,6 +339,18 @@ export function activate(context: vscode.ExtensionContext) {
);
}

const handleButtonPressTelemetry = (buttonState: any) => {
if (buttonState["button_a"] && buttonState["button_b"]) {
TelemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_BUTTON_AB);
} else if (buttonState["button_a"]) {
TelemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_BUTTON_A);
} else if (buttonState["button_b"]) {
TelemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_BUTTON_B);
} else if (buttonState["switch"]) {
TelemetryAI.trackFeatureUsage(TelemetryEventName.SIMULATOR_SWITCH);
}
}

const updatePythonExtraPaths = () => {
const pathToLib: string = __dirname;
const currentExtraPaths: string[] =
Expand Down
17 changes: 8 additions & 9 deletions src/telemetry/telemetryAI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ import TelemetryReporter from "vscode-extension-telemetry";
import getPackageInfo from "./getPackageInfo";

// tslint:disable-next-line:export-name
export default class TelmemetryAI {
export default class TelemetryAI {
static trackFeatureUsage(eventName: string, eventProperties?: { [key: string]: string }) {
TelemetryAI.telemetryReporter.sendTelemetryEvent(eventName, eventProperties);
}

private static telemetryReporter: TelemetryReporter;

constructor(private vscodeContext: vscode.ExtensionContext) {
TelmemetryAI.telemetryReporter = this.createTelemetryReporter(vscodeContext);
constructor(vscodeContext: vscode.ExtensionContext) {
TelemetryAI.telemetryReporter = this.createTelemetryReporter(vscodeContext);
}

public getExtensionName(context: vscode.ExtensionContext): string {
Expand All @@ -24,11 +28,6 @@ export default class TelmemetryAI {
this.trackTimeDuration(eventName, startTime, endTime, eventProperties);
}

public trackFeatureUsage(eventName: string, eventProperties?: { [key: string]: string }) {
const measurement = {};
TelmemetryAI.telemetryReporter.sendTelemetryEvent(eventName, eventProperties, measurement);
}

private createTelemetryReporter(context: vscode.ExtensionContext): TelemetryReporter {
const { extensionName, extensionVersion, instrumentationKey } = getPackageInfo(context);
const reporter: TelemetryReporter = new TelemetryReporter(extensionName, extensionVersion, instrumentationKey);
Expand All @@ -41,6 +40,6 @@ export default class TelmemetryAI {
duration: (endTime - startTime) / 1000
}
// Only send event if telemetry is not suppressed
TelmemetryAI.telemetryReporter.sendTelemetryEvent(eventName, properties, measurement);
TelemetryAI.telemetryReporter.sendTelemetryEvent(eventName, properties, measurement);
}
}

0 comments on commit bceaca8

Please sign in to comment.