aboutsummaryrefslogblamecommitdiffstats
path: root/packages/website/ts/utils/analytics.ts
blob: f4bfa083fff72fc9eef2bd25da3782dcc0f407b2 (plain) (tree)
1
2
3
4
5
6
7
8
9
10

                                    
                                        

                                           

                          
                  

                                                        
                                                                                  






                       
                                                                       
                                      



                                                                                        


                                                      
import * as _ from 'lodash';
import * as ReactGA from 'react-ga';
import { InjectedWeb3 } from 'ts/types';
import { configs } from 'ts/utils/configs';
import { utils } from 'ts/utils/utils';

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