Move out generating of event properties, and send in orderSource

This commit is contained in:
Steve Klebanoff 2018-11-20 14:59:23 -08:00
parent ba41fc9275
commit 6124d80c89
2 changed files with 24 additions and 8 deletions

View File

@ -126,14 +126,7 @@ export class ZeroExInstantProvider extends React.Component<ZeroExInstantProvider
// Analytics
disableAnalytics(this.props.shouldDisableAnalyticsTracking || false);
analytics.addEventProperties({
embeddedHost: window.location.host,
embeddedUrl: window.location.href,
networkId: state.network,
providerName: state.providerState.name,
gitSha: process.env.GIT_SHA,
npmVersion: process.env.NPM_PACKAGE_VERSION,
});
analytics.addEventProperties(analytics.generateEventProperties(state, window));
analytics.trackInstantOpened();
}
public componentWillUnmount(): void {

View File

@ -1,5 +1,8 @@
import { BasicOrderProvider, StandardRelayerAPIOrderProvider } from '@0x/asset-buyer';
import { ObjectMap } from '@0x/types';
import { State } from '../redux/reducer';
import { heapUtil } from './heap';
let isDisabled = false;
@ -47,6 +50,7 @@ export interface AnalyticsEventOptions {
providerName?: string;
gitSha?: string;
npmVersion?: string;
orderSource?: string;
}
export const analytics = {
addUserProperties: (properties: AnalyticsUserOptions): void => {
@ -59,6 +63,25 @@ export const analytics = {
heapUtil.evaluateHeapCall(heap => heap.addEventProperties(properties));
});
},
generateEventProperties: (state: State, window: Window): AnalyticsEventOptions => {
let orderSource = 'unknown';
const orderProvider = state.providerState.assetBuyer.orderProvider;
if (orderProvider instanceof StandardRelayerAPIOrderProvider) {
orderSource = orderProvider.apiUrl;
} else if (orderProvider instanceof BasicOrderProvider) {
orderSource = 'provided';
}
return {
embeddedHost: window.location.host,
embeddedUrl: window.location.href,
networkId: state.network,
providerName: state.providerState.name,
gitSha: process.env.GIT_SHA,
npmVersion: process.env.NPM_PACKAGE_VERSION,
orderSource,
};
},
trackWalletReady: trackingEventFnWithoutPayload(EventNames.WALLET_READY),
trackInstantOpened: trackingEventFnWithoutPayload(EventNames.INSTANT_OPENED),
};