@standardnotes/analytics
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [1.2.0](https://github.com/standardnotes/snjs/compare/@standardnotes/analytics@1.1.0...@standardnotes/analytics@1.2.0) (2022-05-26) | ||
### Features | ||
* add activity indicators in analytics ([e6f5b5a](https://github.com/standardnotes/snjs/commit/e6f5b5afbff1f5f96adfcba42f4708fa74ac7f80)) | ||
# [1.1.0](https://github.com/standardnotes/snjs/compare/@standardnotes/analytics@1.0.7...@standardnotes/analytics@1.1.0) (2022-05-24) | ||
@@ -8,0 +19,0 @@ |
export declare enum AnalyticsActivity { | ||
EditingItems = "editing-items" | ||
EditingItems = "editing-items", | ||
Login = "login" | ||
} |
@@ -7,2 +7,3 @@ "use strict"; | ||
AnalyticsActivity["EditingItems"] = "editing-items"; | ||
AnalyticsActivity["Login"] = "login"; | ||
})(AnalyticsActivity = exports.AnalyticsActivity || (exports.AnalyticsActivity = {})); |
@@ -7,2 +7,6 @@ import { AnalyticsActivity } from './AnalyticsActivity'; | ||
markActivity(activity: AnalyticsActivity, analyticsId: number): Promise<void>; | ||
wasActivityDoneYesterday(activity: AnalyticsActivity, analyticsId: number): Promise<boolean>; | ||
wasActivityDoneToday(activity: AnalyticsActivity, analyticsId: number): Promise<boolean>; | ||
wasActivityDoneLastWeek(activity: AnalyticsActivity, analyticsId: number): Promise<boolean>; | ||
wasActivityDoneThisWeek(activity: AnalyticsActivity, analyticsId: number): Promise<boolean>; | ||
getYesterdaySNJSUsage(): Promise<Array<{ | ||
@@ -9,0 +13,0 @@ version: string; |
@@ -7,2 +7,6 @@ import * as IORedis from 'ioredis'; | ||
constructor(redisClient: IORedis.Redis); | ||
wasActivityDoneYesterday(activity: AnalyticsActivity, analyticsId: number): Promise<boolean>; | ||
wasActivityDoneToday(activity: AnalyticsActivity, analyticsId: number): Promise<boolean>; | ||
wasActivityDoneLastWeek(activity: AnalyticsActivity, analyticsId: number): Promise<boolean>; | ||
wasActivityDoneThisWeek(activity: AnalyticsActivity, analyticsId: number): Promise<boolean>; | ||
markActivity(activity: AnalyticsActivity, analyticsId: number): Promise<void>; | ||
@@ -29,2 +33,3 @@ getYesterdayOutOfSyncIncidents(): Promise<number>; | ||
private getYesterdayDate; | ||
private getLastWeekDate; | ||
} |
@@ -17,2 +17,26 @@ "use strict"; | ||
} | ||
wasActivityDoneYesterday(activity, analyticsId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const bitValue = yield this.redisClient.getbit(`bitmap:action:${activity}:timespan:${this.getDailyKey(this.getYesterdayDate())}`, analyticsId); | ||
return bitValue === 1; | ||
}); | ||
} | ||
wasActivityDoneToday(activity, analyticsId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const bitValue = yield this.redisClient.getbit(`bitmap:action:${activity}:timespan:${this.getDailyKey()}`, analyticsId); | ||
return bitValue === 1; | ||
}); | ||
} | ||
wasActivityDoneLastWeek(activity, analyticsId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const bitValue = yield this.redisClient.getbit(`bitmap:action:${activity}:timespan:${this.getWeeklyKey(this.getLastWeekDate())}`, analyticsId); | ||
return bitValue === 1; | ||
}); | ||
} | ||
wasActivityDoneThisWeek(activity, analyticsId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const bitValue = yield this.redisClient.getbit(`bitmap:action:${activity}:timespan:${this.getWeeklyKey()}`, analyticsId); | ||
return bitValue === 1; | ||
}); | ||
} | ||
markActivity(activity, analyticsId) { | ||
@@ -86,4 +110,4 @@ return __awaiter(this, void 0, void 0, function* () { | ||
} | ||
getWeeklyKey() { | ||
const date = new Date(); | ||
getWeeklyKey(date) { | ||
date = date !== null && date !== void 0 ? date : new Date(); | ||
const firstJanuary = new Date(date.getFullYear(), 0, 1); | ||
@@ -108,3 +132,8 @@ const numberOfDaysPassed = Math.floor((date.getTime() - firstJanuary.getTime()) / (24 * 60 * 60 * 1000)); | ||
} | ||
getLastWeekDate() { | ||
const yesterday = new Date(); | ||
yesterday.setDate(new Date().getDate() - 7); | ||
return yesterday; | ||
} | ||
} | ||
exports.RedisAnalyticsStore = RedisAnalyticsStore; |
@@ -21,3 +21,32 @@ "use strict"; | ||
redisClient.setbit = jest.fn(); | ||
redisClient.getbit = jest.fn().mockReturnValue(1); | ||
}); | ||
it('shoud tell if activity was done yesterday', () => __awaiter(void 0, void 0, void 0, function* () { | ||
jest.useFakeTimers('modern'); | ||
jest.setSystemTime(1653395155000); | ||
yield createStore().wasActivityDoneYesterday(Domain_1.AnalyticsActivity.EditingItems, 123); | ||
jest.useRealTimers(); | ||
expect(redisClient.getbit).toHaveBeenCalledWith('bitmap:action:editing-items:timespan:2022-5-23', 123); | ||
})); | ||
it('shoud tell if activity was done today', () => __awaiter(void 0, void 0, void 0, function* () { | ||
jest.useFakeTimers('modern'); | ||
jest.setSystemTime(1653395155000); | ||
yield createStore().wasActivityDoneToday(Domain_1.AnalyticsActivity.EditingItems, 123); | ||
jest.useRealTimers(); | ||
expect(redisClient.getbit).toHaveBeenCalledWith('bitmap:action:editing-items:timespan:2022-5-24', 123); | ||
})); | ||
it('shoud tell if activity was done last week', () => __awaiter(void 0, void 0, void 0, function* () { | ||
jest.useFakeTimers('modern'); | ||
jest.setSystemTime(1653395155000); | ||
yield createStore().wasActivityDoneLastWeek(Domain_1.AnalyticsActivity.EditingItems, 123); | ||
jest.useRealTimers(); | ||
expect(redisClient.getbit).toHaveBeenCalledWith('bitmap:action:editing-items:timespan:2022-week-20', 123); | ||
})); | ||
it('shoud tell if activity was done this week', () => __awaiter(void 0, void 0, void 0, function* () { | ||
jest.useFakeTimers('modern'); | ||
jest.setSystemTime(1653395155000); | ||
yield createStore().wasActivityDoneThisWeek(Domain_1.AnalyticsActivity.EditingItems, 123); | ||
jest.useRealTimers(); | ||
expect(redisClient.getbit).toHaveBeenCalledWith('bitmap:action:editing-items:timespan:2022-week-21', 123); | ||
})); | ||
it('should set analytics activity', () => __awaiter(void 0, void 0, void 0, function* () { | ||
@@ -24,0 +53,0 @@ jest.useFakeTimers('modern'); |
{ | ||
"name": "@standardnotes/analytics", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"engines": { | ||
@@ -39,3 +39,3 @@ "node": ">=14.0.0 <17.0.0" | ||
}, | ||
"gitHead": "6adf95dc0c18302041b47f5e3fb3c06f5ce11e35" | ||
"gitHead": "ba963c7ccb5e03aae29572b3e1972c62e0160f1d" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21555
369