blob: 30193839e2a7069aefc7032bb4226cb436cdf60c (
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
|
import { ObjectMap } from '@0x/types';
import { heapUtil } from './heap';
enum EventNames {
WALLET_OPENED = 'Wallet - 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);
};
}
function trackingEventFnWithPayload<T extends ObjectMap<string | number>>(
eventName: EventNames,
): (eventDataProperties: T) => void {
return (eventDataProperties: T) => {
track(eventName, eventDataProperties);
};
}
export const analytics = {
// TODO(sk): make these more specific
addUserProperties: (properties: ObjectMap<string | number>): void => {
heapUtil.evaluateHeapCall(heap => heap.addUserProperties(properties));
},
addEventProperties: (properties: ObjectMap<string | number>): void => {
heapUtil.evaluateHeapCall(heap => heap.addEventProperties(properties));
},
walletOpened: trackingEventFnWithoutPayload(EventNames.WALLET_OPENED),
walletReady: trackingEventFnWithPayload<{ numAssetsAvailable: number }>(EventNames.WALLET_READY),
widgetOpened: trackingEventFnWithoutPayload(EventNames.WIDGET_OPENED),
};
|