Track numberAvailableAssets, selectedAssetName, selectedAssetData event properties

This commit is contained in:
Steve Klebanoff
2018-11-26 15:51:40 -08:00
parent d5898a3a05
commit 7610130f73
3 changed files with 33 additions and 5 deletions

View File

@@ -131,6 +131,7 @@ export class ZeroExInstantProvider extends React.Component<ZeroExInstantProvider
this.props.orderSource, this.props.orderSource,
state.providerState, state.providerState,
window, window,
state.selectedAsset,
this.props.affiliateInfo, this.props.affiliateInfo,
), ),
); );

View File

@@ -55,10 +55,25 @@ export const analyticsMiddleware: Middleware = store => next => middlewareAction
} }
break; break;
case ActionTypes.UPDATE_SELECTED_ASSET: case ActionTypes.UPDATE_SELECTED_ASSET:
if (curState.selectedAsset) { const selectedAsset = curState.selectedAsset;
if (selectedAsset) {
const assetName = selectedAsset.metaData.name;
const assetData = selectedAsset.assetData;
analytics.trackTokenSelectorChose({ analytics.trackTokenSelectorChose({
assetName: curState.selectedAsset.metaData.name, assetName,
assetData: curState.selectedAsset.assetData, assetData,
});
analytics.addEventProperties({
selectedAssetName: assetName,
selectedAssetData: assetData,
});
}
break;
case ActionTypes.SET_AVAILABLE_ASSETS:
const availableAssets = curState.availableAssets;
if (availableAssets) {
analytics.addEventProperties({
numberAvailableAssets: availableAssets.length,
}); });
} }
break; break;

View File

@@ -1,4 +1,4 @@
import { AffiliateInfo, Network, OrderSource, ProviderState } from '../types'; import { AffiliateInfo, Asset, Network, OrderSource, ProviderState } from '../types';
import { EventProperties, heapUtil } from './heap'; import { EventProperties, heapUtil } from './heap';
@@ -25,6 +25,7 @@ enum EventNames {
TOKEN_SELECTOR_CHOSE = 'Token Selector - Chose', TOKEN_SELECTOR_CHOSE = 'Token Selector - Chose',
TOKEN_SELECTOR_SEARCHED = 'Token Selector - Searched', TOKEN_SELECTOR_SEARCHED = 'Token Selector - Searched',
} }
const track = (eventName: EventNames, eventProperties: EventProperties = {}): void => { const track = (eventName: EventNames, eventProperties: EventProperties = {}): void => {
evaluateIfEnabled(() => { evaluateIfEnabled(() => {
heapUtil.evaluateHeapCall(heap => heap.track(eventName, eventProperties)); heapUtil.evaluateHeapCall(heap => heap.track(eventName, eventProperties));
@@ -56,6 +57,9 @@ export interface AnalyticsEventOptions {
orderSource?: string; orderSource?: string;
affiliateAddress?: string; affiliateAddress?: string;
affiliateFeePercent?: number; affiliateFeePercent?: number;
numberAvailableAssets?: number;
selectedAssetName?: string;
selectedAssetData?: string;
} }
export enum TokenSelectorClosedVia { export enum TokenSelectorClosedVia {
ClickedX = 'Clicked X', ClickedX = 'Clicked X',
@@ -77,12 +81,13 @@ export const analytics = {
orderSource: OrderSource, orderSource: OrderSource,
providerState: ProviderState, providerState: ProviderState,
window: Window, window: Window,
selectedAsset?: Asset,
affiliateInfo?: AffiliateInfo, affiliateInfo?: AffiliateInfo,
): AnalyticsEventOptions => { ): AnalyticsEventOptions => {
const affiliateAddress = affiliateInfo ? affiliateInfo.feeRecipient : 'none'; const affiliateAddress = affiliateInfo ? affiliateInfo.feeRecipient : 'none';
const affiliateFeePercent = affiliateInfo ? parseFloat(affiliateInfo.feePercentage.toFixed(4)) : 0; const affiliateFeePercent = affiliateInfo ? parseFloat(affiliateInfo.feePercentage.toFixed(4)) : 0;
const orderSourceName = typeof orderSource === 'string' ? orderSource : 'provided'; const orderSourceName = typeof orderSource === 'string' ? orderSource : 'provided';
return { const eventOptions: AnalyticsEventOptions = {
embeddedHost: window.location.host, embeddedHost: window.location.host,
embeddedUrl: window.location.href, embeddedUrl: window.location.href,
networkId: network, networkId: network,
@@ -93,6 +98,13 @@ export const analytics = {
affiliateAddress, affiliateAddress,
affiliateFeePercent, affiliateFeePercent,
}; };
if (selectedAsset) {
eventOptions.selectedAssetName = selectedAsset.metaData.name;
eventOptions.selectedAssetData = selectedAsset.assetData;
}
return eventOptions;
}, },
trackInstantOpened: trackingEventFnWithoutPayload(EventNames.INSTANT_OPENED), trackInstantOpened: trackingEventFnWithoutPayload(EventNames.INSTANT_OPENED),
trackAccountLocked: trackingEventFnWithoutPayload(EventNames.ACCOUNT_LOCKED), trackAccountLocked: trackingEventFnWithoutPayload(EventNames.ACCOUNT_LOCKED),