mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-19 13:47:54 +00:00
Merge pull request #1106 from balena-io/roman/analytics-fix
event-tracker: Use std mixpanel types
This commit is contained in:
commit
f8cfdebba8
@ -2,8 +2,7 @@ import * as Bluebird from 'bluebird';
|
||||
import mask = require('json-mask');
|
||||
import * as _ from 'lodash';
|
||||
import * as memoizee from 'memoizee';
|
||||
|
||||
import Mixpanel = require('mixpanel');
|
||||
import * as mixpanel from 'mixpanel';
|
||||
|
||||
import { ConfigType } from './config';
|
||||
import log from './lib/supervisor-console';
|
||||
@ -35,7 +34,7 @@ const mixpanelMask = [
|
||||
|
||||
export class EventTracker {
|
||||
private defaultProperties: EventTrackProperties | null;
|
||||
private client: any;
|
||||
private client: mixpanel.Mixpanel | null;
|
||||
|
||||
public constructor() {
|
||||
this.client = null;
|
||||
@ -54,10 +53,10 @@ export class EventTracker {
|
||||
uuid,
|
||||
supervisorVersion,
|
||||
};
|
||||
if (unmanaged || mixpanelHost == null) {
|
||||
if (unmanaged || mixpanelHost == null || mixpanelToken == null) {
|
||||
return;
|
||||
}
|
||||
this.client = Mixpanel.init(mixpanelToken, {
|
||||
this.client = mixpanel.init(mixpanelToken, {
|
||||
host: mixpanelHost.host,
|
||||
path: mixpanelHost.path,
|
||||
});
|
||||
@ -94,7 +93,9 @@ export class EventTracker {
|
||||
// Call this function at maximum once every minute
|
||||
return _.throttle(
|
||||
properties => {
|
||||
this.client.track(event, properties);
|
||||
if (this.client != null) {
|
||||
this.client.track(event, properties);
|
||||
}
|
||||
},
|
||||
eventDebounceTime,
|
||||
{ leading: true },
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { Mixpanel } from 'mixpanel';
|
||||
import * as mixpanel from 'mixpanel';
|
||||
import { stub } from 'sinon';
|
||||
import { SinonStub, stub } from 'sinon';
|
||||
|
||||
import { expect } from './lib/chai-config';
|
||||
|
||||
@ -9,12 +10,16 @@ import supervisorVersion = require('../src/lib/supervisor-version');
|
||||
describe('EventTracker', () => {
|
||||
let eventTrackerOffline: EventTracker;
|
||||
let eventTracker: EventTracker;
|
||||
let initStub: SinonStub;
|
||||
|
||||
before(() => {
|
||||
stub(mixpanel, 'init').callsFake(token => ({
|
||||
token,
|
||||
track: stub().returns(undefined),
|
||||
}));
|
||||
initStub = stub(mixpanel, 'init').callsFake(
|
||||
token =>
|
||||
(({
|
||||
token,
|
||||
track: stub().returns(undefined),
|
||||
} as unknown) as Mixpanel),
|
||||
);
|
||||
|
||||
eventTrackerOffline = new EventTracker();
|
||||
eventTracker = new EventTracker();
|
||||
@ -23,7 +28,7 @@ describe('EventTracker', () => {
|
||||
|
||||
after(() => {
|
||||
(EventTracker.prototype as any).logEvent.restore();
|
||||
return mixpanel.init.restore();
|
||||
return initStub.restore();
|
||||
});
|
||||
|
||||
it('initializes in unmanaged mode', () => {
|
||||
|
1
typings/mixpanel.d.ts
vendored
1
typings/mixpanel.d.ts
vendored
@ -1 +0,0 @@
|
||||
declare module 'mixpanel';
|
Loading…
Reference in New Issue
Block a user