diff --git a/package.json b/package.json index c6f4393e..e18a0948 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,7 @@ "lodash": "^4.16.3", "log-timestamp": "^0.1.2", "memoizee": "^0.4.1", - "mixpanel": "0.0.20", + "mixpanel": "https://github.com/balena-io-modules/mixpanel-node", "mkdirp": "^0.5.1", "mocha": "^5.1.1", "mochainon": "^2.0.0", diff --git a/src/config/functions.ts b/src/config/functions.ts index 870324c6..6b1c30a7 100644 --- a/src/config/functions.ts +++ b/src/config/functions.ts @@ -1,6 +1,7 @@ import * as Bluebird from 'bluebird'; import { Transaction } from 'knex'; import * as _ from 'lodash'; +import { URL } from 'url'; import Config = require('../config'); import supervisorVersion = require('../lib/supervisor-version'); @@ -107,7 +108,8 @@ export function createProviderFunctions( mixpanelHost: { get: () => { return config.get('apiEndpoint').then(apiEndpoint => { - return `${apiEndpoint}/mixpanel`; + const url = new URL(apiEndpoint as string); + return { host: url.host, path: '/mixpanel' }; }); }, }, diff --git a/src/event-tracker.ts b/src/event-tracker.ts index 89364b84..fd2deca5 100644 --- a/src/event-tracker.ts +++ b/src/event-tracker.ts @@ -12,7 +12,7 @@ export type EventTrackProperties = Dictionary; interface InitArgs { uuid: string; offlineMode: boolean; - mixpanelHost: string; + mixpanelHost: { host: string; path: string }; mixpanelToken: string; } @@ -55,7 +55,10 @@ export class EventTracker { if (offlineMode) { return; } - this.client = Mixpanel.init(mixpanelToken, { host: mixpanelHost }); + this.client = Mixpanel.init(mixpanelToken, { + host: mixpanelHost.host, + path: mixpanelHost.path, + }); }); } diff --git a/test/09-event-tracker.spec.coffee b/test/09-event-tracker.spec.coffee index 40b31412..cda2ecc0 100644 --- a/test/09-event-tracker.spec.coffee +++ b/test/09-event-tracker.spec.coffee @@ -27,6 +27,7 @@ describe 'EventTracker', -> promise = @eventTrackerOffline.init({ offlineMode: true uuid: 'foobar' + mixpanelHost: { host: '', path: '' } }) expect(promise).to.be.fulfilled .then => @@ -40,6 +41,7 @@ describe 'EventTracker', -> promise = @eventTracker.init({ mixpanelToken: 'someToken' uuid: 'barbaz' + mixpanelHost: { host: '', path: '' } }) expect(promise).to.be.fulfilled .then =>