forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add survey and banner #7
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d5d5482
added feeback and survey
DonJayamanne f0dedaf
moved telemetry files into its own folder
DonJayamanne e2cb832
track whether user responded to feedback
DonJayamanne a512db7
introduce constants
DonJayamanne 3bbc7c1
fix formatting of type
DonJayamanne 9e5b160
track whether user responded to feedback prompt
DonJayamanne d1ac3a6
check whether to display banner
DonJayamanne cad7d7c
code review comments
DonJayamanne 81b583f
Merge branch 'SurveyAndBanner' of https://github.com/Microsoft/vscode…
DonJayamanne 0241e75
code review comments
DonJayamanne 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 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,47 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
'use strict'; | ||
|
||
import * as child_process from 'child_process'; | ||
import * as os from 'os'; | ||
import { window } from 'vscode'; | ||
import { IPersistentStateFactory, PersistentState } from './common/persistentState'; | ||
|
||
const BANNER_URL = 'https://aka.ms/egv4z1'; | ||
|
||
export class BannerService { | ||
private shouldShowBanner: PersistentState<boolean>; | ||
constructor(persistentStateFactory: IPersistentStateFactory) { | ||
this.shouldShowBanner = persistentStateFactory.createGlobalPersistentState('SHOW_NEW_EXT_BANNER', true); | ||
this.showBanner(); | ||
} | ||
private showBanner() { | ||
if (!this.shouldShowBanner.value) { | ||
return; | ||
} | ||
this.shouldShowBanner.value = false; | ||
|
||
const message = 'Would you like to know what is new?'; | ||
const yesButton = 'Yes'; | ||
window.showInformationMessage(message, yesButton).then((value) => { | ||
if (value === yesButton) { | ||
this.displayBanner(); | ||
} | ||
}); | ||
} | ||
private displayBanner() { | ||
let openCommand: string | undefined; | ||
if (os.platform() === 'win32') { | ||
openCommand = 'explorer'; | ||
} else if (os.platform() === 'darwin') { | ||
openCommand = '/usr/bin/open'; | ||
} else { | ||
openCommand = '/usr/bin/xdg-open'; | ||
} | ||
if (!openCommand) { | ||
console.error(`Unable open ${BANNER_URL} on platform '${os.platform()}'.`); | ||
} | ||
child_process.spawn(openCommand, [BANNER_URL]); | ||
} | ||
} |
This file contains 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,33 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
'use strict'; | ||
|
||
import { Memento } from 'vscode'; | ||
|
||
export class PersistentState<T> { | ||
constructor(private storage: Memento, private key: string, private defaultValue: T) { } | ||
|
||
public get value(): T { | ||
return this.storage.get<T>(this.key, this.defaultValue); | ||
} | ||
|
||
public set value(newValue: T) { | ||
this.storage.update(this.key, newValue); | ||
} | ||
} | ||
|
||
export interface IPersistentStateFactory { | ||
createGlobalPersistentState<T>(key: string, defaultValue: T): PersistentState<T>; | ||
createWorkspacePersistentState<T>(key: string, defaultValue: T): PersistentState<T>; | ||
} | ||
|
||
export class PersistentStateFactory implements IPersistentStateFactory { | ||
constructor(private globalState: Memento, private workspaceState: Memento) { } | ||
public createGlobalPersistentState<T>(key: string, defaultValue: T): PersistentState<T> { | ||
return new PersistentState<T>(this.globalState, key, defaultValue); | ||
} | ||
public createWorkspacePersistentState<T>(key: string, defaultValue: T): PersistentState<T> { | ||
return new PersistentState<T>(this.workspaceState, key, defaultValue); | ||
} | ||
} |
This file contains 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 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 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,52 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
'use strict'; | ||
|
||
import { EventEmitter } from 'events'; | ||
|
||
const THRESHOLD_FOR_FEATURE_USAGE = 1000; | ||
const THRESHOLD_FOR_TEXT_EDIT = 5000; | ||
|
||
const FEARTURES_USAGE_COUNTER = 'FEARTURES_USAGE'; | ||
const TEXT_EDIT_COUNTER = 'TEXT_EDIT'; | ||
type counters = 'FEARTURES_USAGE' | 'TEXT_EDIT'; | ||
|
||
export class FeedbackCounters extends EventEmitter { | ||
private counters = new Map<string, { counter: number, threshold: number }>(); | ||
constructor() { | ||
super(); | ||
this.createCounters(); | ||
} | ||
public incrementEditCounter(): void { | ||
this.incrementCounter(TEXT_EDIT_COUNTER); | ||
} | ||
public incrementFeatureUsageCounter(): void { | ||
this.incrementCounter(FEARTURES_USAGE_COUNTER); | ||
} | ||
private createCounters() { | ||
this.counters.set(TEXT_EDIT_COUNTER, { counter: 0, threshold: THRESHOLD_FOR_TEXT_EDIT }); | ||
this.counters.set(FEARTURES_USAGE_COUNTER, { counter: 0, threshold: THRESHOLD_FOR_FEATURE_USAGE }); | ||
} | ||
private incrementCounter(counterName: counters): void { | ||
if (!this.counters.has(counterName)) { | ||
console.error(`Counter ${counterName} not supported in the feedback module of the Python Extension`); | ||
return; | ||
} | ||
|
||
// tslint:disable-next-line:no-non-null-assertion | ||
const value = this.counters.get(counterName)!; | ||
value.counter += 1; | ||
|
||
this.checkThreshold(counterName); | ||
} | ||
private checkThreshold(counterName: string) { | ||
// tslint:disable-next-line:no-non-null-assertion | ||
const value = this.counters.get(counterName)!; | ||
if (value.counter < value.threshold) { | ||
return; | ||
} | ||
|
||
this.emit('thresholdReached'); | ||
} | ||
} |
This file contains 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,128 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
'use strict'; | ||
|
||
import * as child_process from 'child_process'; | ||
import * as os from 'os'; | ||
import { window } from 'vscode'; | ||
import { commands, Disposable, TextDocument, workspace } from 'vscode'; | ||
import { PythonLanguage } from '../common/constants'; | ||
import { IPersistentStateFactory, PersistentState } from '../common/persistentState'; | ||
import { FEEDBACK } from '../telemetry/constants'; | ||
import { captureTelemetry, sendTelemetryEvent } from '../telemetry/index'; | ||
import { FeedbackCounters } from './counters'; | ||
|
||
const FEEDBACK_URL = 'https://aka.ms/egv4z1'; | ||
|
||
export class FeedbackService implements Disposable { | ||
private counters?: FeedbackCounters; | ||
private showFeedbackPrompt: PersistentState<boolean>; | ||
private userResponded: PersistentState<boolean>; | ||
private promptDisplayed: boolean; | ||
private disposables: Disposable[] = []; | ||
private get canShowPrompt(): boolean { | ||
return this.showFeedbackPrompt.value && !this.userResponded.value && | ||
!this.promptDisplayed && this.counters !== undefined; | ||
} | ||
constructor(persistentStateFactory: IPersistentStateFactory) { | ||
this.showFeedbackPrompt = persistentStateFactory.createGlobalPersistentState('SHOW_FEEDBACK_PROMPT', true); | ||
this.userResponded = persistentStateFactory.createGlobalPersistentState('RESPONDED_TO_FEEDBACK', false); | ||
if (this.showFeedbackPrompt.value && !this.userResponded.value) { | ||
this.initialize(); | ||
} | ||
} | ||
public dispose() { | ||
this.counters = undefined; | ||
this.disposables.forEach(disposable => { | ||
// tslint:disable-next-line:no-unsafe-any | ||
disposable.dispose(); | ||
}); | ||
this.disposables = []; | ||
} | ||
private initialize() { | ||
// tslint:disable-next-line:no-void-expression | ||
let commandDisable = commands.registerCommand('python.updateFeedbackCounter', (telemetryEventName: string) => this.updateFeedbackCounter(telemetryEventName)); | ||
this.disposables.push(commandDisable); | ||
// tslint:disable-next-line:no-void-expression | ||
commandDisable = workspace.onDidChangeTextDocument(changeEvent => this.handleChangesToTextDocument(changeEvent.document), this, this.disposables); | ||
this.disposables.push(commandDisable); | ||
|
||
this.counters = new FeedbackCounters(); | ||
this.counters.on('thresholdReached', () => { | ||
this.thresholdHandler(); | ||
}); | ||
} | ||
private handleChangesToTextDocument(textDocument: TextDocument) { | ||
if (textDocument.languageId !== PythonLanguage.language) { | ||
return; | ||
} | ||
if (!this.canShowPrompt) { | ||
return; | ||
} | ||
this.counters.incrementEditCounter(); | ||
} | ||
private updateFeedbackCounter(telemetryEventName: string): void { | ||
// Ignore feedback events. | ||
if (telemetryEventName === FEEDBACK) { | ||
return; | ||
} | ||
if (!this.canShowPrompt) { | ||
return; | ||
} | ||
this.counters.incrementFeatureUsageCounter(); | ||
} | ||
private thresholdHandler() { | ||
if (!this.canShowPrompt) { | ||
return; | ||
} | ||
this.showPrompt(); | ||
} | ||
private showPrompt() { | ||
this.promptDisplayed = true; | ||
|
||
const message = 'Would you tell us how likely you are to recommend the Python extension for VS Code to a friend or colleague?'; | ||
const yesButton = 'Yes'; | ||
const dontShowAgainButton = 'Don\'t Show Again'; | ||
window.showInformationMessage(message, yesButton, dontShowAgainButton).then((value) => { | ||
switch (value) { | ||
case yesButton: { | ||
this.displaySurvey(); | ||
break; | ||
} | ||
case dontShowAgainButton: { | ||
this.doNotShowFeedbackAgain(); | ||
break; | ||
} | ||
default: { | ||
sendTelemetryEvent(FEEDBACK, undefined, { action: 'dismissed' }); | ||
break; | ||
} | ||
} | ||
// Stop everything for this session. | ||
this.dispose(); | ||
}); | ||
} | ||
@captureTelemetry(FEEDBACK, { action: 'accepted' }) | ||
private displaySurvey() { | ||
this.userResponded.value = true; | ||
|
||
let openCommand: string | undefined; | ||
if (os.platform() === 'win32') { | ||
openCommand = 'explorer'; | ||
} else if (os.platform() === 'darwin') { | ||
openCommand = '/usr/bin/open'; | ||
} else { | ||
openCommand = '/usr/bin/xdg-open'; | ||
} | ||
if (!openCommand) { | ||
console.error(`Unable to determine platform to capture user feedback in Python extension ${os.platform()}`); | ||
console.error(`Survey link is: ${FEEDBACK_URL}`); | ||
} | ||
child_process.spawn(openCommand, [FEEDBACK_URL]); | ||
} | ||
@captureTelemetry(FEEDBACK, { action: 'doNotShowAgain' }) | ||
private doNotShowFeedbackAgain() { | ||
this.showFeedbackPrompt.value = false; | ||
} | ||
} |
This file contains 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,6 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
'use strict'; | ||
|
||
export * from './feedbackService'; | ||
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. What's this file for? Simplifying the namespace? 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. yes, |
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this code common between here and the banner? Should it be factored out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but the banner would go out (removed), hence didn't want to share any code.