From f07c8e78b7facc8e2c829606d7b57174234da5fc Mon Sep 17 00:00:00 2001 From: sngrover Date: Thu, 11 Apr 2019 18:06:53 +0530 Subject: [PATCH 1/2] Changes to send data only once per 24 hours --- .../default/HealthData/HealthDataManager.js | 25 +++++++++++-------- src/utils/HealthLogger.js | 7 ++++-- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/extensions/default/HealthData/HealthDataManager.js b/src/extensions/default/HealthData/HealthDataManager.js index a452a4e5471..e6a72b5a181 100644 --- a/src/extensions/default/HealthData/HealthDataManager.js +++ b/src/extensions/default/HealthData/HealthDataManager.js @@ -308,22 +308,16 @@ define(function (require, exports, module) { isHDTracking = prefs.get("healthDataTracking"), isEventDataAlreadySent; - var options = { - location: { - scope: "default" - } - }; - if (isHDTracking) { - isEventDataAlreadySent = PreferencesManager.getViewState(Eventparams.eventName); - PreferencesManager.setViewState(Eventparams.eventName, 1, options); + isEventDataAlreadySent = HealthLogger.analyticsEventMap.get(Eventparams.eventName); + HealthLogger.analyticsEventMap.set(Eventparams.eventName, true); if (!isEventDataAlreadySent || forceSend) { sendAnalyticsDataToServer(Eventparams) .done(function () { - PreferencesManager.setViewState(Eventparams.eventName, 1, options); + HealthLogger.analyticsEventMap.set(Eventparams.eventName, true); result.resolve(); }).fail(function () { - PreferencesManager.setViewState(Eventparams.eventName, 0, options); + HealthLogger.analyticsEventMap.set(Eventparams.eventName, false); result.reject(); }); } else { @@ -336,6 +330,17 @@ define(function (require, exports, module) { return result.promise(); } + /** + * This function is auto called after 24 hours to empty the map + * Map is used to make sure that we send an event only once per 24 hours + **/ + + function emptyAnalyticsMap() { + HealthLogger.analyticsEventMap.clear(); + setTimeout(emptyAnalyticsMap, ONE_DAY); + } + setTimeout(emptyAnalyticsMap, ONE_DAY); + // Expose a command to test data sending capability, but limit it to dev environment only CommandManager.register("Sends health data and Analytics data for testing purpose", "sendHealthData", function() { if (brackets.config.environment === "stage") { diff --git a/src/utils/HealthLogger.js b/src/utils/HealthLogger.js index 3fd5e3d7e74..53631406101 100644 --- a/src/utils/HealthLogger.js +++ b/src/utils/HealthLogger.js @@ -36,7 +36,8 @@ define(function (require, exports, module) { EventDispatcher = require("utils/EventDispatcher"), HEALTH_DATA_STATE_KEY = "HealthData.Logs", - logHealthData = true; + logHealthData = true, + analyticsEventMap = new Map(); var commonStrings = { USAGE: "usage", FILE_OPEN: "fileOpen", @@ -319,9 +320,10 @@ define(function (require, exports, module) { * needs to be logged- should be a js var compatible string */ function sendAnalyticsData(eventName, eventCategory, eventSubCategory, eventType, eventSubType) { - var isEventDataAlreadySent = PreferencesManager.getViewState(eventName), + var isEventDataAlreadySent = analyticsEventMap.get(eventName), isHDTracking = PreferencesManager.getExtensionPrefs("healthData").get("healthDataTracking"), eventParams = {}; + if (isHDTracking && !isEventDataAlreadySent && eventName && eventCategory) { eventParams = { eventName: eventName, @@ -363,4 +365,5 @@ define(function (require, exports, module) { // A new search context on search bar up-Gives an idea of number of times user did a discrete search exports.SEARCH_NEW = "searchNew"; exports.commonStrings = commonStrings; + exports.analyticsEventMap = analyticsEventMap; }); From df09acd044c67399998e82168ac642e785a83a64 Mon Sep 17 00:00:00 2001 From: Snchit Grover Date: Fri, 12 Apr 2019 22:00:32 +0530 Subject: [PATCH 2/2] Update HealthLogger.js --- src/utils/HealthLogger.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/HealthLogger.js b/src/utils/HealthLogger.js index 53631406101..1ac31aa182a 100644 --- a/src/utils/HealthLogger.js +++ b/src/utils/HealthLogger.js @@ -24,6 +24,7 @@ /** * Utilities functions related to Health Data logging */ +/*global Map*/ define(function (require, exports, module) { "use strict";