aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/util/heap.ts
diff options
context:
space:
mode:
authorSteve Klebanoff <steve.klebanoff@gmail.com>2018-11-17 02:10:55 +0800
committerSteve Klebanoff <steve.klebanoff@gmail.com>2018-11-17 02:10:55 +0800
commitdb7f74f99f7790297e737165a0fc9742fe3daf06 (patch)
tree534def102e052766c72bfb4d1306a9a261cc57ed /packages/instant/src/util/heap.ts
parent45a1899eade34e90801e3fbcba9a6789e43684f4 (diff)
downloaddexon-sol-tools-db7f74f99f7790297e737165a0fc9742fe3daf06.tar
dexon-sol-tools-db7f74f99f7790297e737165a0fc9742fe3daf06.tar.gz
dexon-sol-tools-db7f74f99f7790297e737165a0fc9742fe3daf06.tar.bz2
dexon-sol-tools-db7f74f99f7790297e737165a0fc9742fe3daf06.tar.lz
dexon-sol-tools-db7f74f99f7790297e737165a0fc9742fe3daf06.tar.xz
dexon-sol-tools-db7f74f99f7790297e737165a0fc9742fe3daf06.tar.zst
dexon-sol-tools-db7f74f99f7790297e737165a0fc9742fe3daf06.zip
Switch heap id on environment, and make sure app id is what we expect
Diffstat (limited to 'packages/instant/src/util/heap.ts')
-rw-r--r--packages/instant/src/util/heap.ts16
1 files changed, 14 insertions, 2 deletions
diff --git a/packages/instant/src/util/heap.ts b/packages/instant/src/util/heap.ts
index e697562e4..88f65c1ab 100644
--- a/packages/instant/src/util/heap.ts
+++ b/packages/instant/src/util/heap.ts
@@ -1,12 +1,13 @@
import { ObjectMap } from '@0x/types';
import { logUtils } from '@0x/utils';
-import { ANALYTICS_ENABLED, HEAP_ANALYTICS_DEVELOPMENT_APP_ID } from '../constants';
+import { ANALYTICS_ENABLED, HEAP_ANALYTICS_DEVELOPMENT_APP_ID, HEAP_ANALYTICS_PRODUCTION_APP_ID } from '../constants';
import { AnalyticsEventOptions, AnalyticsUserOptions } from './analytics';
export interface HeapAnalytics {
loaded: boolean;
+ appid: string;
identify(id: string, idType: string): void;
track(eventName: string, eventProperties?: ObjectMap<string | number>): void;
resetIdentity(): void;
@@ -23,6 +24,13 @@ const getWindow = (): ModifiedWindow => {
return window as ModifiedWindow;
};
+const getHeapAppId = (): string => {
+ if (process.env.NODE_ENV === 'production') {
+ return HEAP_ANALYTICS_PRODUCTION_APP_ID;
+ }
+ return HEAP_ANALYTICS_DEVELOPMENT_APP_ID;
+};
+
const setupZeroExInstantHeap = () => {
const curWindow = getWindow();
// Set property to specify that this is zeroEx's heap
@@ -64,7 +72,7 @@ const setupZeroExInstantHeap = () => {
(window as any).heap[p[c]] = o(p[c]);
});
// TODO: use production heap id once environment utils merged
- (window as any).heap.load(HEAP_ANALYTICS_DEVELOPMENT_APP_ID);
+ (window as any).heap.load(getHeapAppId());
/* tslint:enable */
return curWindow.heap as HeapAnalytics;
@@ -93,6 +101,10 @@ export const heapUtil = {
const curHeap = heapUtil.getHeap();
if (curHeap) {
try {
+ if (curHeap.appid !== getHeapAppId()) {
+ // Integrator has included heap after us and reset the app id
+ return;
+ }
heapFunctionCall(curHeap);
} catch (e) {
// We never want analytics to crash our React component