From 5e89d2383cc1f0726555fc0a4aa9a0b87e348046 Mon Sep 17 00:00:00 2001 From: Yifang Ma Date: Wed, 28 Oct 2020 12:45:23 -0700 Subject: [PATCH] fix issue for asking repeatly --- utils/eventtracking.js | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/utils/eventtracking.js b/utils/eventtracking.js index 9fd13909..ec35b2b6 100644 --- a/utils/eventtracking.js +++ b/utils/eventtracking.js @@ -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; @@ -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)) { @@ -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.` + @@ -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); } };