diff options
Diffstat (limited to 'packages/instant/src/util/analytics.ts')
-rw-r--r-- | packages/instant/src/util/analytics.ts | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/packages/instant/src/util/analytics.ts b/packages/instant/src/util/analytics.ts index 2ffaac1dd..d790ec1e7 100644 --- a/packages/instant/src/util/analytics.ts +++ b/packages/instant/src/util/analytics.ts @@ -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), }; |