aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/utils/analytics.ts
blob: 37c47c7b0f87a156a74cdcdd2dda2e8b8af2f813 (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
import * as _ from 'lodash';
import * as ReactGA from 'react-ga';
import { configs } from 'ts/utils/configs';
import { utils } from 'ts/utils/utils';
import * as Web3 from 'web3';

export const analytics = {
    init() {
        ReactGA.initialize(configs.GOOGLE_ANALYTICS_ID);
    },
    logEvent(category: string, action: string, label: string, value?: any) {
        ReactGA.event({
            category,
            action,
            label,
            value,
        });
    },
    async logProviderAsync(web3IfExists: Web3) {
        await utils.onPageLoadAsync();
        const providerType = !_.isUndefined(web3IfExists)
            ? utils.getProviderType(web3IfExists.currentProvider)
            : 'NONE';
        ReactGA.ga('set', 'dimension1', providerType);
    },
};