mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
- Add some type script types for better editor experience - Remove redundent global of a singleton Signed-off-by: Sebastian Malton <smalton@mirantis.com> remove references to double statics Signed-off-by: Sebastian Malton <smalton@mirantis.com> fix mocking of user-store Signed-off-by: Sebastian Malton <smalton@mirantis.com>
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import ua from "universal-analytics"
|
|
import { machineIdSync } from 'node-machine-id'
|
|
import { UserStore } from "../common/user-store"
|
|
|
|
const GA_ID = "UA-159377374-1"
|
|
|
|
export class Tracker {
|
|
protected visitor: ua.Visitor
|
|
protected machineId: string = null;
|
|
protected ip: string = null;
|
|
protected appVersion: string;
|
|
protected locale: string;
|
|
protected electronUA: string;
|
|
|
|
constructor(app: Electron.App) {
|
|
try {
|
|
this.visitor = ua(GA_ID, machineIdSync(), {strictCidFormat: false})
|
|
} catch (error) {
|
|
this.visitor = ua(GA_ID)
|
|
}
|
|
this.visitor.set("dl", "https://lensapptelemetry.lakendlabs.com")
|
|
}
|
|
|
|
public async event(eventCategory: string, eventAction: string) {
|
|
return new Promise(async (resolve, reject) => {
|
|
if (!this.telemetryAllowed()) {
|
|
resolve()
|
|
return
|
|
}
|
|
this.visitor.event({
|
|
ec: eventCategory,
|
|
ea: eventAction
|
|
}).send()
|
|
resolve()
|
|
})
|
|
}
|
|
|
|
protected telemetryAllowed() {
|
|
const userPrefs = UserStore.getInstance().getPreferences()
|
|
return !!userPrefs.allowTelemetry
|
|
}
|
|
}
|