Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Changes to send data only once per 24 hours #14695

Merged
merged 2 commits into from
Apr 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions src/extensions/default/HealthData/HealthDataManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
shubhsnov marked this conversation as resolved.
Show resolved Hide resolved
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 {
Expand All @@ -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();
shubhsnov marked this conversation as resolved.
Show resolved Hide resolved
setTimeout(emptyAnalyticsMap, ONE_DAY);
}
setTimeout(emptyAnalyticsMap, ONE_DAY);
shubhsnov marked this conversation as resolved.
Show resolved Hide resolved

// 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") {
Expand Down
8 changes: 6 additions & 2 deletions src/utils/HealthLogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
/**
* Utilities functions related to Health Data logging
*/
/*global Map*/
define(function (require, exports, module) {
"use strict";

Expand All @@ -36,7 +37,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",
Expand Down Expand Up @@ -319,9 +321,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,
Expand Down Expand Up @@ -363,4 +366,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;
});