aboutsummaryrefslogblamecommitdiffstats
path: root/packages/instant/src/util/analytics.ts
blob: 3e2a996cf879d440a02eaa14b2ca458c1250fd01 (plain) (tree)
1
2
3
4
5




                                                 








                                                                                    

         
  
 













                                                                                       
import { ObjectMap } from '@0x/types';
import { logUtils } from '@0x/utils';

import { HeapAnalytics, heapUtil } from './heap';

const evaluteHeapCall = (heapFunctionCall: (heap: HeapAnalytics) => void): void => {
    const curHeap = heapUtil.getHeap();
    if (curHeap) {
        try {
            heapFunctionCall(curHeap);
        } catch (e) {
            // We never want analytics to crash our React component
            // TODO: error reporter here
            logUtils.log('Analytics error', e);
        }
    }
};

export const analytics = {
    addUserProperties: (properties: ObjectMap<string | number>): void => {
        console.log('HEAP: adding user properties', properties);
        evaluteHeapCall(heap => heap.addUserProperties(properties));
    },
    addEventProperties: (properties: ObjectMap<string | number>): void => {
        console.log('HEAP: adding user properties', properties);
        evaluteHeapCall(heap => heap.addEventProperties(properties));
    },
    track: (eventName: string, eventProperties?: ObjectMap<string | number>): void => {
        console.log('HEAP: tracking', eventName, eventProperties);
        evaluteHeapCall(heap => heap.track(eventName, eventProperties));
    },
};