analytics-client
Advanced tools
Comparing version 0.4.4 to 0.5.0-roman-web-289c3a57409b06c021cd7ce594d814c8a6ccc05b
@@ -7,2 +7,7 @@ # Change Log | ||
# v0.5.0 | ||
## (2020-04-13) | ||
* Add WebTracker interface [Roman Mazur] | ||
# v0.4.4 | ||
@@ -9,0 +14,0 @@ ## (2020-04-01) |
export { AnalyticsUrlParams } from './src/url-params'; | ||
export { Client, Config, createClient } from './src/client'; | ||
export { Experiment, LocalExperiment } from './src/experiment'; | ||
export { WebTracker, createWebTracker } from './src/web'; |
@@ -9,2 +9,4 @@ "use strict"; | ||
exports.LocalExperiment = experiment_1.LocalExperiment; | ||
var web_1 = require("./src/web"); | ||
exports.createWebTracker = web_1.createWebTracker; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "analytics-client", | ||
"version": "0.4.4", | ||
"version": "0.5.0-roman-web-289c3a57409b06c021cd7ce594d814c8a6ccc05b", | ||
"description": "Convenient builders to compose analytics tools", | ||
@@ -5,0 +5,0 @@ "repository": { |
import amplitude = require('amplitude-js'); | ||
import { Mixpanel } from 'mixpanel-browser'; | ||
export interface Properties { | ||
[key: string]: any; | ||
} | ||
export interface Client { | ||
@@ -7,2 +10,3 @@ amplitude(): amplitude.AmplitudeClient; | ||
linkDevices(userId: string, deviceIds: string[]): void; | ||
track(eventType: string, props?: Properties): void; | ||
} | ||
@@ -12,2 +16,4 @@ export interface Config { | ||
projectName: string; | ||
componentName: string; | ||
componentVersion?: string; | ||
amplitude?: Exclude<AmplitudeOverride, amplitude.Config>; | ||
@@ -19,4 +25,6 @@ mixpanelInstance?: Mixpanel; | ||
cookieExpiration?: number; | ||
includeReferrer?: boolean; | ||
includeUtm?: boolean; | ||
} | ||
export declare function createClient(config: Config): Client; | ||
export {}; |
@@ -9,3 +9,3 @@ "use strict"; | ||
var identifyObject = function () { | ||
return new amplitude.Identify().set('AnalyticsClientVersion', package_json_1.version); | ||
return new amplitude.Identify().set(config_1.USER_PROP_ANALYTICS_CLIENT_VERSION, package_json_1.version); | ||
}; | ||
@@ -21,4 +21,10 @@ var DefaultClient = (function () { | ||
amplConfig.cookieExpiration = config_1.COOKIES_TTL_DAYS; | ||
amplConfig.includeReferrer = true; | ||
amplConfig.includeUtm = true; | ||
this.amplitudeInstance.init(config.projectName, undefined, amplConfig); | ||
this.checkMixpanelUsage(); | ||
this.amplitudeInstance.identify(new amplitude.Identify().set(config_1.USER_PROP_COMPONENT_NAME, config.componentName)); | ||
if (config.componentVersion) { | ||
this.amplitudeInstance.setVersionName(config.componentVersion); | ||
} | ||
} | ||
@@ -65,2 +71,5 @@ DefaultClient.prototype.checkMixpanelUsage = function () { | ||
}; | ||
DefaultClient.prototype.track = function (eventType, props) { | ||
this.amplitudeInstance.logEvent(eventType, props); | ||
}; | ||
return DefaultClient; | ||
@@ -67,0 +76,0 @@ }()); |
export declare const URL_PARAM_DEVICE_ID = "d_id"; | ||
export declare const COOKIES_DEVICE_IDS = "__analytics_dids"; | ||
export declare const COOKIES_TTL_DAYS = 300; | ||
export declare const USER_PROP_COMPONENT_NAME = "ComponentName"; | ||
export declare const USER_PROP_ANALYTICS_CLIENT_VERSION = "AnalyticsClientVersion"; |
@@ -6,2 +6,4 @@ "use strict"; | ||
exports.COOKIES_TTL_DAYS = 300; | ||
exports.USER_PROP_COMPONENT_NAME = 'ComponentName'; | ||
exports.USER_PROP_ANALYTICS_CLIENT_VERSION = 'AnalyticsClientVersion'; | ||
//# sourceMappingURL=config.js.map |
@@ -7,2 +7,3 @@ "use strict"; | ||
projectName: 'balena-test', | ||
componentName: 'test', | ||
}); | ||
@@ -15,2 +16,3 @@ expect(client.deviceId()).toBeTruthy(); | ||
endpoint: "non-existing-endpoint", | ||
componentName: 'test', | ||
}); | ||
@@ -28,2 +30,3 @@ var identifyCallsCount = 0; | ||
endpoint: "some.host", | ||
componentName: 'test', | ||
}); | ||
@@ -30,0 +33,0 @@ expect(client.amplitude().options.apiEndpoint).toEqual('some.host/amplitude'); |
@@ -65,2 +65,3 @@ "use strict"; | ||
projectName: 'balena-test', | ||
componentName: 'test', | ||
}); | ||
@@ -67,0 +68,0 @@ var identifyCallsCount = 0; |
@@ -26,1 +26,4 @@ const client = analyticsClient.createClient({ | ||
console.log('Variation:', exp.engage(client.deviceId())); | ||
const webTracker = analyticsClient.createWebTracker(client); | ||
webTracker.trackPageView(); |
export { AnalyticsUrlParams } from './src/url-params'; | ||
export { Client, Config, createClient } from './src/client'; | ||
export { Experiment, LocalExperiment } from './src/experiment'; | ||
export { WebTracker, createWebTracker } from './src/web'; |
{ | ||
"name": "analytics-client", | ||
"version": "0.4.4", | ||
"version": "0.5.0-roman-web-289c3a57409b06c021cd7ce594d814c8a6ccc05b", | ||
"description": "Convenient builders to compose analytics tools", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -6,4 +6,12 @@ import amplitude = require('amplitude-js'); | ||
import { version } from '../package.json'; | ||
import { COOKIES_TTL_DAYS } from './config'; | ||
import { | ||
COOKIES_TTL_DAYS, | ||
USER_PROP_ANALYTICS_CLIENT_VERSION, | ||
USER_PROP_COMPONENT_NAME, | ||
} from './config'; | ||
export interface Properties { | ||
[key: string]: any; | ||
} | ||
/** | ||
@@ -21,2 +29,5 @@ * Client defines an interface for interaction wih balena analytics backend. | ||
linkDevices(userId: string, deviceIds: string[]): void; | ||
/** Track event of the defined type with specified event properties. */ | ||
track(eventType: string, props?: Properties): void; | ||
} | ||
@@ -32,6 +43,10 @@ | ||
projectName: string; | ||
/** Name of the component that does the reporting. */ | ||
componentName: string; | ||
/** Component version name. */ | ||
componentVersion?: string; | ||
/** Optional config for Amplitude client. */ | ||
amplitude?: Exclude<AmplitudeOverride, amplitude.Config>; | ||
/** Optional miixpanel client instance. */ | ||
/** Optional mixpanel client instance. */ | ||
mixpanelInstance?: Mixpanel; | ||
@@ -43,6 +58,8 @@ } | ||
cookieExpiration?: number; | ||
includeReferrer?: boolean; | ||
includeUtm?: boolean; | ||
} | ||
const identifyObject = () => | ||
new amplitude.Identify().set('AnalyticsClientVersion', version); | ||
new amplitude.Identify().set(USER_PROP_ANALYTICS_CLIENT_VERSION, version); | ||
@@ -59,8 +76,23 @@ class DefaultClient implements Client { | ||
} | ||
// TODO: Move this to the web tracker. | ||
amplConfig.cookieExpiration = COOKIES_TTL_DAYS; | ||
amplConfig.includeReferrer = true; | ||
amplConfig.includeUtm = true; | ||
this.amplitudeInstance.init(config.projectName, undefined, amplConfig); | ||
this.checkMixpanelUsage(); | ||
this.amplitudeInstance.identify( | ||
new amplitude.Identify().set( | ||
USER_PROP_COMPONENT_NAME, | ||
config.componentName, | ||
), | ||
); | ||
if (config.componentVersion) { | ||
this.amplitudeInstance.setVersionName(config.componentVersion); | ||
} | ||
} | ||
private checkMixpanelUsage() { | ||
// TODO: Move this to the web tracker. | ||
const mp = this.config.mixpanelInstance; | ||
@@ -114,2 +146,6 @@ | ||
} | ||
track(eventType: string, props?: Properties): void { | ||
this.amplitudeInstance.logEvent(eventType, props); | ||
} | ||
} | ||
@@ -116,0 +152,0 @@ |
@@ -6,1 +6,4 @@ /** Query parameter name used to pass device ID between sites. */ | ||
export const COOKIES_TTL_DAYS = 300; | ||
export const USER_PROP_COMPONENT_NAME = 'ComponentName'; | ||
export const USER_PROP_ANALYTICS_CLIENT_VERSION = 'AnalyticsClientVersion'; |
@@ -6,2 +6,3 @@ import { createClient } from '../src/client'; | ||
projectName: 'balena-test', | ||
componentName: 'test', | ||
}); | ||
@@ -15,2 +16,3 @@ expect(client.deviceId()).toBeTruthy(); | ||
endpoint: `non-existing-endpoint`, | ||
componentName: 'test', | ||
}); | ||
@@ -31,4 +33,5 @@ | ||
endpoint: `some.host`, | ||
componentName: 'test', | ||
}); | ||
expect(client.amplitude().options.apiEndpoint).toEqual('some.host/amplitude'); | ||
}); |
@@ -67,2 +67,3 @@ import { createClient } from '../src/client'; | ||
projectName: 'balena-test', | ||
componentName: 'test', | ||
}); | ||
@@ -69,0 +70,0 @@ let identifyCallsCount = 0; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
249668
52
1561