Skip to content

Commit

Permalink
Capture eligibility state (#2063)
Browse files Browse the repository at this point in the history
* Capture eligibility state

* Don't activate surveys during tests
  • Loading branch information
bwateratmsft authored Jun 11, 2020
1 parent 718d393 commit ba8b4df
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/telemetry/surveys/SurveyManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface Survey {

export class SurveyManager {
public activate(): void {
if (!ext.telemetryOptIn) {
if (!ext.telemetryOptIn || ext.runningTests) {
return;
}

Expand All @@ -44,7 +44,22 @@ export class SurveyManager {

private async executeSurvey(survey: Survey): Promise<void> {
try {
if (await this.shouldShowPrompt(survey)) {
const shouldShowPrompt: boolean = await callWithTelemetryAndErrorHandling('surveyCheck', async (context: IActionContext) => {
context.telemetry.properties.surveyId = survey.id;
context.telemetry.properties.isActivationEvent = 'true';

const responded = ext.context.globalState.get<boolean>(`${surveyRespondedKeyPrefix}.${survey.id}`, false);
const eligible = await survey.isEligible();
const flighted = await ext.experimentationService.isFlightEnabled(`${surveyFlightPrefix}.${survey.id}`);

context.telemetry.properties.surveyResponded = responded.toString();
context.telemetry.properties.surveyEligible = eligible.toString();
context.telemetry.properties.surveyFlighted = flighted.toString();

return !responded && eligible && flighted;
});

if (shouldShowPrompt) {
await callWithTelemetryAndErrorHandling('surveyResponse', async (context: IActionContext) => {
context.telemetry.properties.surveyId = survey.id;
context.telemetry.properties.isActivationEvent = 'true';
Expand Down Expand Up @@ -73,10 +88,4 @@ export class SurveyManager {

return result === take;
}

private async shouldShowPrompt(survey: Survey): Promise<boolean> {
return ext.context.globalState.get<boolean>(`${surveyRespondedKeyPrefix}.${survey.id}`, false) !== true &&
await survey.isEligible() &&
await ext.experimentationService.isFlightEnabled(`${surveyFlightPrefix}.${survey.id}`);
}
}

0 comments on commit ba8b4df

Please sign in to comment.