aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/util/analytics.ts
diff options
context:
space:
mode:
authorSteve Klebanoff <steve.klebanoff@gmail.com>2018-11-17 08:44:23 +0800
committerSteve Klebanoff <steve.klebanoff@gmail.com>2018-11-17 08:44:23 +0800
commit3f0d94c83872ae80d6377fd4f712efa4c174a284 (patch)
tree87757d2a96c2a4f295de0be2256afe8f6fc76842 /packages/instant/src/util/analytics.ts
parent097bfe581dff6ff77e3cf19a03138743ae13868e (diff)
downloaddexon-0x-contracts-3f0d94c83872ae80d6377fd4f712efa4c174a284.tar.gz
dexon-0x-contracts-3f0d94c83872ae80d6377fd4f712efa4c174a284.tar.zst
dexon-0x-contracts-3f0d94c83872ae80d6377fd4f712efa4c174a284.zip
Add way to disable via props
Diffstat (limited to 'packages/instant/src/util/analytics.ts')
-rw-r--r--packages/instant/src/util/analytics.ts23
1 files changed, 20 insertions, 3 deletions
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),