-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
report processed analytics event (#204)
- Loading branch information
Showing
5 changed files
with
62 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { AnalyticsEvent } from "./anyltics-event" | ||
import { analytics } from "../analytics" | ||
|
||
jest.mock("../analytics") | ||
|
||
|
||
describe("AnalyticEvents", () => { | ||
describe("isAnalyticEnabled", () => { | ||
it("should return true when OPT_OUT_ANALYTICS not set", function () { | ||
const isEnabled = AnalyticsEvent.isAnalyticEnabled() | ||
expect(isEnabled).toEqual(true) | ||
}) | ||
|
||
it("should return true when OPT_OUT_ANALYTICS not disabled", function () { | ||
process.env.OPT_OUT_ANALYTICS = "false" | ||
const isEnabled = AnalyticsEvent.isAnalyticEnabled() | ||
expect(isEnabled).toEqual(true) | ||
}) | ||
it("should return false when OPT_OUT_ANALYTICS disabled", function () { | ||
process.env.OPT_OUT_ANALYTICS = "true" | ||
const isEnabled = AnalyticsEvent.isAnalyticEnabled() | ||
expect(isEnabled).toEqual(false) | ||
}) | ||
}) | ||
describe("reportProcessingFinished", () => { | ||
it("should not track the event when analytics disabled", function () { | ||
process.env.OPT_OUT_ANALYTICS = "true" | ||
const trackMock = (analytics.track as any).mockResolvedValueOnce(undefined) | ||
AnalyticsEvent.reportProcessingFinished() | ||
expect(trackMock).not.toHaveBeenCalled() | ||
|
||
}) | ||
it("should track the even only when analytics enabled", function () { | ||
process.env.OPT_OUT_ANALYTICS = "false" | ||
const trackMock = (analytics.track as any).mockResolvedValueOnce(undefined) | ||
AnalyticsEvent.reportProcessingFinished() | ||
expect(trackMock).toHaveBeenCalled() | ||
}) | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { analytics } from "../analytics" | ||
|
||
export class AnalyticsEvent { | ||
|
||
static isAnalyticEnabled(): boolean { | ||
return !(process.env.OPT_OUT_ANALYTICS === "true") | ||
} | ||
|
||
static reportProcessingFinished() { | ||
if (this.isAnalyticEnabled()) { | ||
console.log(process.env.ANALYTICS_IDENTIFIER) | ||
analytics.track("reportProcessingFinished", { | ||
// eslint-disable-next-line camelcase | ||
distinct_id: process.env.ANALYTICS_IDENTIFIER, | ||
}) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
import { analytics } from "../../analytics" | ||
import { config } from "../../../config"; | ||
|
||
|
||
(async function () { | ||
await analytics.track("appAlive", { | ||
$os: process.platform, | ||
distinct_id: config.analyticsIdentifier, | ||
distinct_id: process.env.ANALYTICS_IDENTIFIER, | ||
}) | ||
}()) | ||
|