diff options
author | Fabio Berger <me@fabioberger.com> | 2018-03-10 23:53:42 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-03-10 23:53:42 +0800 |
commit | cea8dcae3dac2265d3780c95d6581fe48e9b94a4 (patch) | |
tree | 527d82d0123ec38924c4459b833131f379e20f71 /packages/website/ts/utils/analytics.ts | |
parent | fc7e7d9331692510b2cf5baebcff948ebf0afc07 (diff) | |
download | dexon-0x-contracts-cea8dcae3dac2265d3780c95d6581fe48e9b94a4.tar dexon-0x-contracts-cea8dcae3dac2265d3780c95d6581fe48e9b94a4.tar.gz dexon-0x-contracts-cea8dcae3dac2265d3780c95d6581fe48e9b94a4.tar.bz2 dexon-0x-contracts-cea8dcae3dac2265d3780c95d6581fe48e9b94a4.tar.lz dexon-0x-contracts-cea8dcae3dac2265d3780c95d6581fe48e9b94a4.tar.xz dexon-0x-contracts-cea8dcae3dac2265d3780c95d6581fe48e9b94a4.tar.zst dexon-0x-contracts-cea8dcae3dac2265d3780c95d6581fe48e9b94a4.zip |
Refactor Analytics so that calls to ReactGA are all in a single module, combining the provider type util function, moving GA id to configs and using utils.onPageLoadAsync
Diffstat (limited to 'packages/website/ts/utils/analytics.ts')
-rw-r--r-- | packages/website/ts/utils/analytics.ts | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/packages/website/ts/utils/analytics.ts b/packages/website/ts/utils/analytics.ts new file mode 100644 index 000000000..37c47c7b0 --- /dev/null +++ b/packages/website/ts/utils/analytics.ts @@ -0,0 +1,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); + }, +}; |