Skip to content

Commit

Permalink
fix issue for asking repeatly
Browse files Browse the repository at this point in the history
  • Loading branch information
icerove committed Oct 28, 2020
1 parent cae81d2 commit 5e89d23
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions utils/eventtracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const uuid = require('uuid');

const TRACKING_ENABLED_KEY = 'trackingEnabled';
const TRACKING_SESSION_ID_KEY = 'trackingSessionId';
const TRACKING_ID_KEY = 'trackingID';

const isGitPod = () => {
return !!process.env.GITPOD_WORKSPACE_URL;
Expand Down Expand Up @@ -40,6 +41,20 @@ const shouldTrack = (shellSettings) => {
);
};

const shouldTrackID = (shellSettings) => {
return (
TRACKING_ID_KEY in shellSettings &&
shellSettings[TRACKING_ID_KEY]
);
};

const shouldNOTTrackID = (shellSettings) => {
return (
TRACKING_ID_KEY in shellSettings &&
!shellSettings[TRACKING_ID_KEY]
);
};

const track = async (eventType, eventProperties, options) => {
const shellSettings = settings.getShellSettings();
if (!shouldTrack(shellSettings)) {
Expand Down Expand Up @@ -115,7 +130,7 @@ const getIdTrackingConsent = async () => {
output: process.stdout,
});
try {
for (let attempts = 0; attempts < 10; attempts++) {
for (let attempts = 0; attempts < 3; attempts++) {
const answer = await new Promise((resolve) => {
rl.question(
chalk`We would like to help with your development journey with NEAR.` +
Expand Down Expand Up @@ -144,15 +159,19 @@ const getIdTrackingConsent = async () => {
};

const askForId = async (options) => {
const answer = await getIdTrackingConsent();
if(answer){
const shellSettings = settings.getShellSettings();
const shellSettings = settings.getShellSettings();
if(shouldTrackID(shellSettings)){
const id = isGitPod() ? getGitPodUserHash() : shellSettings[TRACKING_SESSION_ID_KEY];
await Promise.all([
mixpanel.alias(options.accountId, id),
mixpanel.people.set({account_id: options.accountId})
mixpanel.people.set_once({account_id: options.accountId})
]);

}else if(shouldNOTTrackID(shellSettings)){
return;
}
else{
shellSettings[TRACKING_ID_KEY] = (await getIdTrackingConsent());
settings.saveShellSettings(shellSettings);
}
};

Expand Down

0 comments on commit 5e89d23

Please sign in to comment.