blob: 4c229be0318c93910e44dd9a68e16fe1067f745d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
import { ObjectMap } from '@0x/types';
import { heapUtil } from './heap';
enum EventNames {
INSTANT_OPENED = 'Instant - Opened',
WALLET_READY = 'Wallet - Ready',
WIDGET_OPENED = 'Widget - Opened',
}
const track = (eventName: EventNames, eventData: ObjectMap<string | number> = {}): void => {
heapUtil.evaluateHeapCall(heap => heap.track(eventName, eventData));
};
function trackingEventFnWithoutPayload(eventName: EventNames): () => void {
return () => {
track(eventName);
};
}
// tslint:disable-next-line:no-unused-variable
function trackingEventFnWithPayload<T extends ObjectMap<string | number>>(
eventName: EventNames,
): (eventDataProperties: T) => void {
return (eventDataProperties: T) => {
track(eventName, eventDataProperties);
};
}
export interface AnalyticsUserOptions {
ethAddress?: string;
ethBalanceInUnitAmount?: string;
}
export interface AnalyticsEventOptions {
embeddedHost?: string;
embeddedUrl?: string;
networkId?: number;
providerName?: string;
gitSha?: string;
npmVersion?: string;
}
export const analytics = {
addUserProperties: (properties: AnalyticsUserOptions): void => {
heapUtil.evaluateHeapCall(heap => heap.addUserProperties(properties));
},
addEventProperties: (properties: AnalyticsEventOptions): void => {
heapUtil.evaluateHeapCall(heap => heap.addEventProperties(properties));
},
trackWalletReady: trackingEventFnWithoutPayload(EventNames.WALLET_READY),
trackWidgetOpened: trackingEventFnWithoutPayload(EventNames.WIDGET_OPENED),
trackInstantOpened: trackingEventFnWithoutPayload(EventNames.INSTANT_OPENED),
};
|