Compare commits

...

5 Commits

Author SHA1 Message Date
Senthamil Sindhu
ad165ae069 Add more logs for NPS 2024-01-23 14:55:00 -08:00
Senthamil Sindhu
913a96afec Fix error in code 2024-01-18 11:11:03 -08:00
Senthamil Sindhu
e26207e949 Address comments 2024-01-18 11:04:24 -08:00
Senthamil Sindhu
5d6273889d Remove lint error 2024-01-18 09:49:34 -08:00
Senthamil Sindhu
889cf77801 Update logic for NPS survey for existing accounts > 90 days 2024-01-18 09:22:46 -08:00

View File

@@ -277,21 +277,32 @@ export default class Explorer {
const NINETY_DAYS_IN_MS = 7776000000; const NINETY_DAYS_IN_MS = 7776000000;
const ONE_DAY_IN_MS = 86400000; const ONE_DAY_IN_MS = 86400000;
const THREE_DAYS_IN_MS = 259200000; const THREE_DAYS_IN_MS = 259200000;
const isAccountNewerThanNinetyDays = isAccountNewerThanThresholdInMs(
userContext.databaseAccount?.systemData?.createdAt || "",
NINETY_DAYS_IN_MS,
);
const lastSubmitted: string = localStorage.getItem("lastSubmitted"); const lastSubmitted: string = localStorage.getItem("lastSubmitted");
Logger.logInfo(`NPS Survey last shown date: ${lastSubmitted}`, "Explorer/openNPSSurveyDialog");
if (lastSubmitted !== null) { if (lastSubmitted !== null) {
Logger.logInfo(`NPS Survey last shown is not empty ${lastSubmitted}`, "Explorer/openNPSSurveyDialog");
let lastSubmittedDate: number = parseInt(lastSubmitted); let lastSubmittedDate: number = parseInt(lastSubmitted);
Logger.logInfo(`NPS Survey last shown is parsed ${lastSubmittedDate.toString()}`, "Explorer/openNPSSurveyDialog");
if (isNaN(lastSubmittedDate)) { if (isNaN(lastSubmittedDate)) {
Logger.logInfo(
`NPS Survey last shown is not a number ${lastSubmittedDate.toString()}`,
"Explorer/openNPSSurveyDialog",
);
lastSubmittedDate = 0; lastSubmittedDate = 0;
} }
const nowMs: number = Date.now(); const nowMs: number = Date.now();
Logger.logInfo(`NPS Survey current date ${nowMs.toString()}`, "Explorer/openNPSSurveyDialog");
const millisecsSinceLastSubmitted = nowMs - lastSubmittedDate; const millisecsSinceLastSubmitted = nowMs - lastSubmittedDate;
if (millisecsSinceLastSubmitted < NINETY_DAYS_IN_MS) { if (millisecsSinceLastSubmitted < NINETY_DAYS_IN_MS) {
Logger.logInfo(
`NPS Survey last shown is less than ninety days ${millisecsSinceLastSubmitted.toString()}`,
"Explorer/openNPSSurveyDialog",
);
return; return;
} }
} }
@@ -299,26 +310,32 @@ export default class Explorer {
// Try Cosmos DB subscription - survey shown to 100% of users at day 1 in Data Explorer. // Try Cosmos DB subscription - survey shown to 100% of users at day 1 in Data Explorer.
if (userContext.isTryCosmosDBSubscription) { if (userContext.isTryCosmosDBSubscription) {
if (isAccountNewerThanThresholdInMs(userContext.databaseAccount?.systemData?.createdAt || "", ONE_DAY_IN_MS)) { if (isAccountNewerThanThresholdInMs(userContext.databaseAccount?.systemData?.createdAt || "", ONE_DAY_IN_MS)) {
Logger.logInfo(
`Displaying NPS Survey for Try Cosmos DB ${userContext.apiType}`,
"Explorer/openNPSSurveyDialog",
);
this.sendNPSMessage(); this.sendNPSMessage();
} }
} else { } else {
// An existing account is older than 3 days but less than 90 days old. For existing account show to 100% of users in Data Explorer. // Show survey when an existing account is older than 3 days
if ( if (
!isAccountNewerThanThresholdInMs(userContext.databaseAccount?.systemData?.createdAt || "", THREE_DAYS_IN_MS) && !isAccountNewerThanThresholdInMs(userContext.databaseAccount?.systemData?.createdAt || "", THREE_DAYS_IN_MS)
isAccountNewerThanNinetyDays
) { ) {
Logger.logInfo(
`Displaying NPS Survey for users with existing ${userContext.apiType} account older than 3 days`,
"Explorer/openNPSSurveyDialog",
);
this.sendNPSMessage(); this.sendNPSMessage();
} else {
// An existing account is greater than 90 days. For existing account show to random 33% of users in Data Explorer.
if (this.getRandomInt(100) < 33) {
this.sendNPSMessage();
}
} }
} }
} }
private sendNPSMessage() { private sendNPSMessage() {
sendMessage({ type: MessageTypes.DisplayNPSSurvey }); sendMessage({ type: MessageTypes.DisplayNPSSurvey });
Logger.logInfo(
`NPS Survey logging current date when survey is shown ${Date.now().toString()}`,
"Explorer/openNPSSurveyDialog",
);
localStorage.setItem("lastSubmitted", Date.now().toString()); localStorage.setItem("lastSubmitted", Date.now().toString());
} }