Merge pull request #1299 from 0xProject/feature/instant/open-close-events

[instant] Add more event properties
This commit is contained in:
Steve Klebanoff
2018-11-26 15:10:50 -08:00
committed by GitHub
2 changed files with 36 additions and 8 deletions

View File

@@ -125,14 +125,15 @@ 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.network,
this.props.orderSource,
state.providerState,
window,
this.props.affiliateInfo,
),
);
analytics.trackInstantOpened();
}
public componentWillUnmount(): void {

View File

@@ -1,3 +1,5 @@
import { AffiliateInfo, Network, OrderSource, ProviderState } from '../types';
import { EventProperties, heapUtil } from './heap';
let isDisabled = false;
@@ -47,6 +49,9 @@ export interface AnalyticsEventOptions {
providerName?: string;
gitSha?: string;
npmVersion?: string;
orderSource?: string;
affiliateAddress?: string;
affiliateFeePercent?: number;
}
export const analytics = {
@@ -60,6 +65,28 @@ export const analytics = {
heapUtil.evaluateHeapCall(heap => heap.addEventProperties(properties));
});
},
generateEventProperties: (
network: Network,
orderSource: OrderSource,
providerState: ProviderState,
window: Window,
affiliateInfo?: AffiliateInfo,
): AnalyticsEventOptions => {
const affiliateAddress = affiliateInfo ? affiliateInfo.feeRecipient : 'none';
const affiliateFeePercent = affiliateInfo ? parseFloat(affiliateInfo.feePercentage.toFixed(4)) : 0;
const orderSourceName = typeof orderSource === 'string' ? orderSource : 'provided';
return {
embeddedHost: window.location.host,
embeddedUrl: window.location.href,
networkId: network,
providerName: providerState.name,
gitSha: process.env.GIT_SHA,
npmVersion: process.env.NPM_PACKAGE_VERSION,
orderSource: orderSourceName,
affiliateAddress,
affiliateFeePercent,
};
},
trackInstantOpened: trackingEventFnWithoutPayload(EventNames.INSTANT_OPENED),
trackAccountLocked: trackingEventFnWithoutPayload(EventNames.ACCOUNT_LOCKED),
trackAccountReady: (address: string) => trackingEventFnWithPayload(EventNames.ACCOUNT_READY)({ address }),