Switch heap id on environment, and make sure app id is what we expect

This commit is contained in:
Steve Klebanoff
2018-11-16 10:10:55 -08:00
parent 45a1899ead
commit db7f74f99f
2 changed files with 16 additions and 3 deletions

View File

@@ -16,8 +16,9 @@ export const BUY_QUOTE_UPDATE_INTERVAL_TIME_MS = ONE_SECOND_MS * 15;
export const DEFAULT_GAS_PRICE = GWEI_IN_WEI.mul(6);
export const DEFAULT_ESTIMATED_TRANSACTION_TIME_MS = ONE_MINUTE_MS * 2;
export const ETH_GAS_STATION_API_BASE_URL = 'https://ethgasstation.info';
export const ANALYTICS_ENABLED = true; // TODO: change when we can switch on dev
export const ANALYTICS_ENABLED = process.env.NODE_ENV === 'production' || process.env.ENABLE_HEAP;
export const HEAP_ANALYTICS_DEVELOPMENT_APP_ID = '507265531';
export const HEAP_ANALYTICS_PRODUCTION_APP_ID = '2323640988';
export const COINBASE_API_BASE_URL = 'https://api.coinbase.com/v2';
export const PROGRESS_STALL_AT_WIDTH = '95%';
export const PROGRESS_FINISH_ANIMATION_TIME_MS = 200;

View File

@@ -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