diff options
author | Steve Klebanoff <steve.klebanoff@gmail.com> | 2018-11-17 08:44:23 +0800 |
---|---|---|
committer | Steve Klebanoff <steve.klebanoff@gmail.com> | 2018-11-17 08:44:23 +0800 |
commit | 3f0d94c83872ae80d6377fd4f712efa4c174a284 (patch) | |
tree | 87757d2a96c2a4f295de0be2256afe8f6fc76842 /packages/instant/src | |
parent | 097bfe581dff6ff77e3cf19a03138743ae13868e (diff) | |
download | dexon-sol-tools-3f0d94c83872ae80d6377fd4f712efa4c174a284.tar dexon-sol-tools-3f0d94c83872ae80d6377fd4f712efa4c174a284.tar.gz dexon-sol-tools-3f0d94c83872ae80d6377fd4f712efa4c174a284.tar.bz2 dexon-sol-tools-3f0d94c83872ae80d6377fd4f712efa4c174a284.tar.lz dexon-sol-tools-3f0d94c83872ae80d6377fd4f712efa4c174a284.tar.xz dexon-sol-tools-3f0d94c83872ae80d6377fd4f712efa4c174a284.tar.zst dexon-sol-tools-3f0d94c83872ae80d6377fd4f712efa4c174a284.zip |
Add way to disable via props
Diffstat (limited to 'packages/instant/src')
-rw-r--r-- | packages/instant/src/components/zero_ex_instant_provider.tsx | 6 | ||||
-rw-r--r-- | packages/instant/src/util/analytics.ts | 23 |
2 files changed, 25 insertions, 4 deletions
diff --git a/packages/instant/src/components/zero_ex_instant_provider.tsx b/packages/instant/src/components/zero_ex_instant_provider.tsx index 1d5e7fe6f..52454148f 100644 --- a/packages/instant/src/components/zero_ex_instant_provider.tsx +++ b/packages/instant/src/components/zero_ex_instant_provider.tsx @@ -12,7 +12,7 @@ import { DEFAULT_STATE, DefaultState, State } from '../redux/reducer'; import { store, Store } from '../redux/store'; import { fonts } from '../style/fonts'; import { AccountState, AffiliateInfo, AssetMetaData, Network, OrderSource } from '../types'; -import { analytics } from '../util/analytics'; +import { analytics, disableAnalytics } from '../util/analytics'; import { assetUtils } from '../util/asset'; import { errorFlasher } from '../util/error_flasher'; import { gasPriceEstimator } from '../util/gas_price_estimator'; @@ -37,6 +37,7 @@ export interface ZeroExInstantProviderOptionalProps { additionalAssetMetaDataMap: ObjectMap<AssetMetaData>; networkId: Network; affiliateInfo: AffiliateInfo; + disableAnalyticsTracking: boolean; } export class ZeroExInstantProvider extends React.Component<ZeroExInstantProviderProps> { @@ -124,6 +125,9 @@ export class ZeroExInstantProvider extends React.Component<ZeroExInstantProvider this._flashErrorIfWrongNetwork(); // Analytics + if (this.props.disableAnalyticsTracking) { + disableAnalytics(); + } analytics.addEventProperties({ embeddedHost: window.location.host, embeddedUrl: window.location.href, diff --git a/packages/instant/src/util/analytics.ts b/packages/instant/src/util/analytics.ts index 1667c246c..ce40d08e7 100644 --- a/packages/instant/src/util/analytics.ts +++ b/packages/instant/src/util/analytics.ts @@ -2,12 +2,25 @@ import { ObjectMap } from '@0x/types'; import { heapUtil } from './heap'; +let disabled = false; +export const disableAnalytics = () => { + disabled = true; +}; +export const evaluateIfEnabled = (fnCall: () => void) => { + if (disabled) { + return; + } + fnCall(); +}; + enum EventNames { INSTANT_OPENED = 'Instant - Opened', WALLET_READY = 'Wallet - Ready', } const track = (eventName: EventNames, eventData: ObjectMap<string | number> = {}): void => { - heapUtil.evaluateHeapCall(heap => heap.track(eventName, eventData)); + evaluateIfEnabled(() => { + heapUtil.evaluateHeapCall(heap => heap.track(eventName, eventData)); + }); }; function trackingEventFnWithoutPayload(eventName: EventNames): () => void { return () => { @@ -37,10 +50,14 @@ export interface AnalyticsEventOptions { } export const analytics = { addUserProperties: (properties: AnalyticsUserOptions): void => { - heapUtil.evaluateHeapCall(heap => heap.addUserProperties(properties)); + evaluateIfEnabled(() => { + heapUtil.evaluateHeapCall(heap => heap.addUserProperties(properties)); + }); }, addEventProperties: (properties: AnalyticsEventOptions): void => { - heapUtil.evaluateHeapCall(heap => heap.addEventProperties(properties)); + evaluateIfEnabled(() => { + heapUtil.evaluateHeapCall(heap => heap.addEventProperties(properties)); + }); }, trackWalletReady: trackingEventFnWithoutPayload(EventNames.WALLET_READY), trackInstantOpened: trackingEventFnWithoutPayload(EventNames.INSTANT_OPENED), |