From ca44cd901b84c887a8e4f74f0904db6add418623 Mon Sep 17 00:00:00 2001 From: Yu Long Date: Fri, 15 Nov 2024 15:13:55 +0100 Subject: [PATCH] refactor(analytics): group some constants together --- .../components/Card/Card.Analytics.test.tsx | 19 +++++++------- .../components/GooglePay/GooglePay.test.ts | 4 +-- .../RedirectShopper/RedirectShopper.tsx | 6 ++++- .../ThreeDS2/ThreeDS2Challenge.test.tsx | 6 ++--- .../components/ThreeDS2/ThreeDS2Challenge.tsx | 4 +-- .../ThreeDS2DeviceFingerprint.test.tsx | 6 ++--- .../ThreeDS2/ThreeDS2DeviceFingerprint.tsx | 4 +-- .../ThreeDS2/callSubmit3DS2Fingerprint.ts | 8 +++--- .../Challenge/PrepareChallenge3DS2.test.tsx | 8 +++--- .../Challenge/PrepareChallenge3DS2.tsx | 12 ++++----- .../PrepareFingerprint3DS2.test.tsx | 6 ++--- .../PrepareFingerprint3DS2.tsx | 4 +-- .../lib/src/core/Analytics/Analytics.test.ts | 4 +-- packages/lib/src/core/Analytics/Analytics.ts | 12 ++++----- .../Analytics/analyticsPreProcessor.test.ts | 14 +++++------ .../core/Analytics/analyticsPreProcessor.ts | 24 ++++++++---------- packages/lib/src/core/Analytics/constants.ts | 25 +++++++++++++------ packages/lib/src/core/Analytics/types.ts | 7 +++--- 18 files changed, 92 insertions(+), 81 deletions(-) diff --git a/packages/lib/src/components/Card/Card.Analytics.test.tsx b/packages/lib/src/components/Card/Card.Analytics.test.tsx index a4b34b106b..c8ad3d7b25 100644 --- a/packages/lib/src/components/Card/Card.Analytics.test.tsx +++ b/packages/lib/src/components/Card/Card.Analytics.test.tsx @@ -8,8 +8,7 @@ let analyticsEventObject; import { ANALYTICS_CONFIGURED_STR, - ANALYTICS_EVENT_INFO, - ANALYTICS_EVENT_LOG, + ANALYTICS_EVENT, ANALYTICS_FOCUS_STR, ANALYTICS_RENDERED_STR, ANALYTICS_SUBMIT_STR, @@ -47,7 +46,7 @@ describe('Card: calls that generate "info" analytics should produce objects with // With configData removed inspect what's left expect(analyticsEventObject).toEqual({ - event: ANALYTICS_EVENT_INFO, + event: ANALYTICS_EVENT.info, data: { component: card.constructor['type'], type: ANALYTICS_RENDERED_STR } }); }); @@ -65,7 +64,7 @@ describe('Card: calls that generate "info" analytics should produce objects with // With configData removed inspect what's left expect(analyticsEventObject).toEqual({ - event: ANALYTICS_EVENT_INFO, + event: ANALYTICS_EVENT.info, data: { component: card.constructor['type'], type: ANALYTICS_RENDERED_STR, isStoredPaymentMethod: true, brand: 'mc' } }); }); @@ -76,7 +75,7 @@ describe('Card: calls that generate "info" analytics should produce objects with }); expect(analyticsModule.createAnalyticsEvent).toHaveBeenCalledWith({ - event: ANALYTICS_EVENT_INFO, + event: ANALYTICS_EVENT.info, data: { component: card.constructor['type'], type: ANALYTICS_CONFIGURED_STR } }); }); @@ -89,7 +88,7 @@ describe('Card: calls that generate "info" analytics should produce objects with }); expect(analyticsModule.createAnalyticsEvent).toHaveBeenCalledWith({ - event: ANALYTICS_EVENT_INFO, + event: ANALYTICS_EVENT.info, data: { component: card.constructor['type'], type: ANALYTICS_CONFIGURED_STR, isStoredPaymentMethod: true, brand: 'mc' } }); }); @@ -109,7 +108,7 @@ describe('Card: calls that generate "info" analytics should produce objects with }); expect(analyticsModule.createAnalyticsEvent).toHaveBeenCalledWith({ - event: ANALYTICS_EVENT_INFO, + event: ANALYTICS_EVENT.info, data: { component: card.constructor['type'], type: ANALYTICS_FOCUS_STR, target: 'card_number' } }); }); @@ -129,7 +128,7 @@ describe('Card: calls that generate "info" analytics should produce objects with }); expect(analyticsModule.createAnalyticsEvent).toHaveBeenCalledWith({ - event: ANALYTICS_EVENT_INFO, + event: ANALYTICS_EVENT.info, data: { component: card.constructor['type'], type: ANALYTICS_UNFOCUS_STR, target: 'card_number' } }); }); @@ -141,7 +140,7 @@ describe('Card: calls that generate "info" analytics should produce objects with }); expect(analyticsModule.createAnalyticsEvent).toHaveBeenCalledWith({ - event: ANALYTICS_EVENT_INFO, + event: ANALYTICS_EVENT.info, data: { component: card.constructor['type'], type: ANALYTICS_VALIDATION_ERROR_STR, @@ -170,7 +169,7 @@ describe('Card: calls that generate "log" analytics should produce objects with card.submitAnalytics({ type: ANALYTICS_SUBMIT_STR }); expect(analyticsModule.createAnalyticsEvent).toHaveBeenCalledWith({ - event: ANALYTICS_EVENT_LOG, + event: ANALYTICS_EVENT.log, data: { component: card.constructor['type'], type: ANALYTICS_SUBMIT_STR, diff --git a/packages/lib/src/components/GooglePay/GooglePay.test.ts b/packages/lib/src/components/GooglePay/GooglePay.test.ts index 9700b65e07..b835e5850b 100644 --- a/packages/lib/src/components/GooglePay/GooglePay.test.ts +++ b/packages/lib/src/components/GooglePay/GooglePay.test.ts @@ -2,7 +2,7 @@ import GooglePay from './GooglePay'; import GooglePayService from './GooglePayService'; import Analytics from '../../core/Analytics'; -import { ANALYTICS_EVENT_INFO, ANALYTICS_SELECTED_STR, NO_CHECKOUT_ATTEMPT_ID } from '../../core/Analytics/constants'; +import { ANALYTICS_EVENT, ANALYTICS_SELECTED_STR, NO_CHECKOUT_ATTEMPT_ID } from '../../core/Analytics/constants'; const analyticsModule = Analytics({ analytics: {}, loadingContext: '', locale: '', clientKey: '', bundleType: 'umd' }); @@ -458,7 +458,7 @@ describe('GooglePay', () => { gpay.submit(); expect(analyticsModule.createAnalyticsEvent).toHaveBeenCalledWith({ - event: ANALYTICS_EVENT_INFO, + event: ANALYTICS_EVENT.info, data: { component: gpay.props.type, type: ANALYTICS_SELECTED_STR, diff --git a/packages/lib/src/components/Redirect/components/RedirectShopper/RedirectShopper.tsx b/packages/lib/src/components/Redirect/components/RedirectShopper/RedirectShopper.tsx index b01693e8ce..0702319c97 100644 --- a/packages/lib/src/components/Redirect/components/RedirectShopper/RedirectShopper.tsx +++ b/packages/lib/src/components/Redirect/components/RedirectShopper/RedirectShopper.tsx @@ -10,12 +10,14 @@ interface RedirectShopperProps { redirectFromTopWhenInIframe?: boolean; paymentMethodType?: string; onActionHandled?: (rtnObj: ActionHandledReturnObject) => void; + onRedirectError?: () => void; } class RedirectShopper extends Component { private postForm; public static defaultProps = { beforeRedirect: resolve => resolve(), + onRedirectError: () => {}, method: 'GET' }; @@ -49,7 +51,9 @@ class RedirectShopper extends Component { }) ); - dispatchEvent.then(doRedirect).catch(() => {}); + dispatchEvent.then(doRedirect).catch(() => { + this.props.onRedirectError(); + }); } render({ url, method, data = {} }) { diff --git a/packages/lib/src/components/ThreeDS2/ThreeDS2Challenge.test.tsx b/packages/lib/src/components/ThreeDS2/ThreeDS2Challenge.test.tsx index 1a015c5f0c..61045730fa 100644 --- a/packages/lib/src/components/ThreeDS2/ThreeDS2Challenge.test.tsx +++ b/packages/lib/src/components/ThreeDS2/ThreeDS2Challenge.test.tsx @@ -1,6 +1,6 @@ import { ThreeDS2Challenge } from './index'; import Analytics from '../../core/Analytics'; -import { ANALYTICS_API_ERROR, Analytics3DS2Errors, ANALYTICS_EVENT_ERROR, ANALYTICS_RENDERED_STR } from '../../core/Analytics/constants'; +import { ANALYTICS_ERROR_TYPE, Analytics3DS2Errors, ANALYTICS_RENDERED_STR, ANALYTICS_EVENT } from '../../core/Analytics/constants'; import { THREEDS2_CHALLENGE_ERROR, THREEDS2_ERROR } from './constants'; const analyticsModule = Analytics({ analytics: {}, loadingContext: '', locale: '', clientKey: '', bundleType: 'umd' }); @@ -31,11 +31,11 @@ describe('ThreeDS2Challenge: calls that generate analytics should produce object const view = challenge.render(); expect(analyticsModule.createAnalyticsEvent).toHaveBeenCalledWith({ - event: ANALYTICS_EVENT_ERROR, + event: ANALYTICS_EVENT.error, data: { component: challenge.constructor['type'], type: THREEDS2_ERROR, - errorType: ANALYTICS_API_ERROR, + errorType: ANALYTICS_ERROR_TYPE.apiError, message: `${THREEDS2_CHALLENGE_ERROR}: Missing 'paymentData' property from threeDS2 action`, code: Analytics3DS2Errors.ACTION_IS_MISSING_PAYMENT_DATA } diff --git a/packages/lib/src/components/ThreeDS2/ThreeDS2Challenge.tsx b/packages/lib/src/components/ThreeDS2/ThreeDS2Challenge.tsx index c336c299c3..7bfbf96a60 100644 --- a/packages/lib/src/components/ThreeDS2/ThreeDS2Challenge.tsx +++ b/packages/lib/src/components/ThreeDS2/ThreeDS2Challenge.tsx @@ -7,7 +7,7 @@ import { hasOwnProperty } from '../../utils/hasOwnProperty'; import { TxVariants } from '../tx-variants'; import { ThreeDS2ChallengeConfiguration } from './types'; import AdyenCheckoutError, { API_ERROR } from '../../core/Errors/AdyenCheckoutError'; -import { ANALYTICS_API_ERROR, Analytics3DS2Errors, ANALYTICS_RENDERED_STR, Analytics3DS2Events } from '../../core/Analytics/constants'; +import { ANALYTICS_ERROR_TYPE, Analytics3DS2Errors, ANALYTICS_RENDERED_STR, Analytics3DS2Events } from '../../core/Analytics/constants'; import { SendAnalyticsObject } from '../../core/Analytics/types'; import { CoreProvider } from '../../core/Context/CoreProvider'; import { ActionHandledReturnObject } from '../../types/global-types'; @@ -61,7 +61,7 @@ class ThreeDS2Challenge extends UIElement { this.submitAnalytics({ type: THREEDS2_ERROR, code: Analytics3DS2Errors.ACTION_IS_MISSING_PAYMENT_DATA, - errorType: ANALYTICS_API_ERROR, + errorType: ANALYTICS_ERROR_TYPE.apiError, message: `${THREEDS2_CHALLENGE_ERROR}: Missing 'paymentData' property from threeDS2 action` }); diff --git a/packages/lib/src/components/ThreeDS2/ThreeDS2DeviceFingerprint.test.tsx b/packages/lib/src/components/ThreeDS2/ThreeDS2DeviceFingerprint.test.tsx index b7abd7abbb..0920a35f9e 100644 --- a/packages/lib/src/components/ThreeDS2/ThreeDS2DeviceFingerprint.test.tsx +++ b/packages/lib/src/components/ThreeDS2/ThreeDS2DeviceFingerprint.test.tsx @@ -1,6 +1,6 @@ import { ThreeDS2DeviceFingerprint } from './index'; import Analytics from '../../core/Analytics'; -import { ANALYTICS_API_ERROR, Analytics3DS2Errors, ANALYTICS_EVENT_ERROR, ANALYTICS_RENDERED_STR } from '../../core/Analytics/constants'; +import { Analytics3DS2Errors, ANALYTICS_RENDERED_STR, ANALYTICS_EVENT, ANALYTICS_ERROR_TYPE } from '../../core/Analytics/constants'; import { THREEDS2_ERROR, THREEDS2_FINGERPRINT_ERROR } from './constants'; const analyticsModule = Analytics({ analytics: {}, loadingContext: '', locale: '', clientKey: '', bundleType: 'umd' }); @@ -32,11 +32,11 @@ describe('ThreeDS2DeviceFingerprint: calls that generate analytics should produc const view = fingerprint.render(); expect(analyticsModule.createAnalyticsEvent).toHaveBeenCalledWith({ - event: ANALYTICS_EVENT_ERROR, + event: ANALYTICS_EVENT.error, data: { component: fingerprint.constructor['type'], type: THREEDS2_ERROR, - errorType: ANALYTICS_API_ERROR, + errorType: ANALYTICS_ERROR_TYPE.apiError, message: `${THREEDS2_FINGERPRINT_ERROR}: Missing 'paymentData' property from threeDS2 action`, code: Analytics3DS2Errors.ACTION_IS_MISSING_PAYMENT_DATA } diff --git a/packages/lib/src/components/ThreeDS2/ThreeDS2DeviceFingerprint.tsx b/packages/lib/src/components/ThreeDS2/ThreeDS2DeviceFingerprint.tsx index cc42630db7..6e547e9785 100644 --- a/packages/lib/src/components/ThreeDS2/ThreeDS2DeviceFingerprint.tsx +++ b/packages/lib/src/components/ThreeDS2/ThreeDS2DeviceFingerprint.tsx @@ -6,7 +6,7 @@ import { existy } from '../../utils/commonUtils'; import { TxVariants } from '../tx-variants'; import { ThreeDS2DeviceFingerprintConfiguration } from './types'; import AdyenCheckoutError, { API_ERROR } from '../../core/Errors/AdyenCheckoutError'; -import { ANALYTICS_API_ERROR, Analytics3DS2Errors, ANALYTICS_RENDERED_STR, Analytics3DS2Events } from '../../core/Analytics/constants'; +import { ANALYTICS_ERROR_TYPE, Analytics3DS2Errors, ANALYTICS_RENDERED_STR, Analytics3DS2Events } from '../../core/Analytics/constants'; import { SendAnalyticsObject } from '../../core/Analytics/types'; import { THREEDS2_ERROR, THREEDS2_FINGERPRINT, THREEDS2_FINGERPRINT_ERROR, THREEDS2_FULL } from './constants'; import { ActionHandledReturnObject } from '../../types/global-types'; @@ -53,7 +53,7 @@ class ThreeDS2DeviceFingerprint extends UIElement { @@ -91,7 +91,7 @@ class PrepareChallenge3DS2 extends Component {}; const baseAnalyticsError = { type: THREEDS2_ERROR, - errorType: ANALYTICS_API_ERROR + errorType: ANALYTICS_ERROR_TYPE.apiError }; let completeFunction: any; @@ -147,7 +147,7 @@ describe('ThreeDS2DeviceFingerprint - flow completes with errors that are consid type: THREEDS2_ERROR, message: 'threeDS2Fingerprint: timeout', code: Analytics3DS2Errors.THREEDS2_TIMEOUT, - errorType: ANALYTICS_NETWORK_ERROR + errorType: ANALYTICS_ERROR_TYPE.network }); // analytics to say process is complete diff --git a/packages/lib/src/components/ThreeDS2/components/DeviceFingerprint/PrepareFingerprint3DS2.tsx b/packages/lib/src/components/ThreeDS2/components/DeviceFingerprint/PrepareFingerprint3DS2.tsx index d0e98322ad..77afc36314 100644 --- a/packages/lib/src/components/ThreeDS2/components/DeviceFingerprint/PrepareFingerprint3DS2.tsx +++ b/packages/lib/src/components/ThreeDS2/components/DeviceFingerprint/PrepareFingerprint3DS2.tsx @@ -15,7 +15,7 @@ import { THREEDS2_ERROR, TIMEOUT } from '../../constants'; -import { ANALYTICS_API_ERROR, ANALYTICS_NETWORK_ERROR, Analytics3DS2Errors, Analytics3DS2Events } from '../../../../core/Analytics/constants'; +import { ANALYTICS_ERROR_TYPE, Analytics3DS2Errors, Analytics3DS2Events } from '../../../../core/Analytics/constants'; class PrepareFingerprint3DS2 extends Component { public static type = 'scheme'; @@ -163,7 +163,7 @@ class PrepareFingerprint3DS2 extends Component { - const arrayName = type === ANALYTICS_EVENT_INFO ? type : `${type}s`; + const addAnalyticsEvent = (type: AnalyticsEvent, obj: AnalyticsObject) => { + const arrayName = type === ANALYTICS_EVENT.info ? type : `${type}s`; eventsQueue.add(`${arrayName}`, obj); /** @@ -38,7 +38,7 @@ const Analytics = ({ locale, clientKey, analytics, amount, analyticsContext, bun * - info events are stored until a log or error comes along, * but, if after a set time, no other analytics event (log or error) has come along then we send the info events anyway */ - if (type === ANALYTICS_EVENT_INFO) { + if (type === ANALYTICS_EVENT.info) { clearTimeout(sendEventsTimerId); sendEventsTimerId = setTimeout(() => void sendAnalyticsEvents(), ANALYTICS_INFO_TIMER_INTERVAL); } @@ -49,7 +49,7 @@ const Analytics = ({ locale, clientKey, analytics, amount, analyticsContext, bun * ...but... tests with the 3DS2 process show that many logs can happen almost at the same time (or you can have an error followed immediately by a log), * so instead of making several sequential api calls we see if we can "batch" them using debounce */ - if (type === ANALYTICS_EVENT_LOG || type === ANALYTICS_EVENT_ERROR) { + if (type === ANALYTICS_EVENT.log || type === ANALYTICS_EVENT.error) { clearTimeout(sendEventsTimerId); // clear any timer that might be about to dispatch the info events array debounce(sendAnalyticsEvents)(); diff --git a/packages/lib/src/core/Analytics/analyticsPreProcessor.test.ts b/packages/lib/src/core/Analytics/analyticsPreProcessor.test.ts index 0ff6b64c4e..02772164fd 100644 --- a/packages/lib/src/core/Analytics/analyticsPreProcessor.test.ts +++ b/packages/lib/src/core/Analytics/analyticsPreProcessor.test.ts @@ -1,7 +1,7 @@ import Analytics from './Analytics'; import { PaymentAmount } from '../../types'; import { analyticsPreProcessor } from './analyticsPreProcessor'; -import { ANALYTICS_EVENT_INFO, ANALYTICS_RENDERED_STR } from './constants'; +import { ANALYTICS_EVENT, ANALYTICS_RENDERED_STR } from './constants'; let analytics; let sendAnalytics; @@ -20,7 +20,7 @@ describe('Testing AnalyticsPreProcessor: process and output', () => { sendAnalytics('paywithgoogle', { type: ANALYTICS_RENDERED_STR }, { isExpress: true, expressPage: 'cart' }); expect(analytics.createAnalyticsEvent).toBeCalledWith({ - event: ANALYTICS_EVENT_INFO, + event: ANALYTICS_EVENT.info, data: { component: 'paywithgoogle', type: 'rendered', @@ -34,7 +34,7 @@ describe('Testing AnalyticsPreProcessor: process and output', () => { sendAnalytics('paywithgoogle', { type: ANALYTICS_RENDERED_STR }, { isExpress: null, expressPage: 'cart' }); expect(analytics.createAnalyticsEvent).toBeCalledWith({ - event: ANALYTICS_EVENT_INFO, + event: ANALYTICS_EVENT.info, data: { component: 'paywithgoogle', type: 'rendered' @@ -46,7 +46,7 @@ describe('Testing AnalyticsPreProcessor: process and output', () => { sendAnalytics('paywithgoogle', { type: ANALYTICS_RENDERED_STR }, { isExpress: undefined, expressPage: 'cart' }); expect(analytics.createAnalyticsEvent).toBeCalledWith({ - event: ANALYTICS_EVENT_INFO, + event: ANALYTICS_EVENT.info, data: { component: 'paywithgoogle', type: 'rendered' @@ -58,7 +58,7 @@ describe('Testing AnalyticsPreProcessor: process and output', () => { sendAnalytics('paywithgoogle', { type: ANALYTICS_RENDERED_STR }, { isExpress: 'true', expressPage: 'cart' }); expect(analytics.createAnalyticsEvent).toBeCalledWith({ - event: ANALYTICS_EVENT_INFO, + event: ANALYTICS_EVENT.info, data: { component: 'paywithgoogle', type: 'rendered' @@ -70,7 +70,7 @@ describe('Testing AnalyticsPreProcessor: process and output', () => { sendAnalytics('paywithgoogle', { type: ANALYTICS_RENDERED_STR }, { isExpress: false, expressPage: 'cart' }); expect(analytics.createAnalyticsEvent).toBeCalledWith({ - event: ANALYTICS_EVENT_INFO, + event: ANALYTICS_EVENT.info, data: { component: 'paywithgoogle', type: 'rendered', @@ -83,7 +83,7 @@ describe('Testing AnalyticsPreProcessor: process and output', () => { sendAnalytics('paywithgoogle', { type: ANALYTICS_RENDERED_STR }, { isExpress: true, expressPage: 'foobar' }); expect(analytics.createAnalyticsEvent).toBeCalledWith({ - event: ANALYTICS_EVENT_INFO, + event: ANALYTICS_EVENT.info, data: { component: 'paywithgoogle', type: 'rendered', diff --git a/packages/lib/src/core/Analytics/analyticsPreProcessor.ts b/packages/lib/src/core/Analytics/analyticsPreProcessor.ts index 4105b550f1..9707a333e7 100644 --- a/packages/lib/src/core/Analytics/analyticsPreProcessor.ts +++ b/packages/lib/src/core/Analytics/analyticsPreProcessor.ts @@ -5,9 +5,6 @@ import { ANALYTICS_CONFIGURED_STR, ANALYTICS_DISPLAYED_STR, ANALYTICS_DOWNLOAD_STR, - ANALYTICS_EVENT_ERROR, - ANALYTICS_EVENT_INFO, - ANALYTICS_EVENT_LOG, ANALYTICS_FOCUS_STR, ANALYTICS_INPUT_STR, ANALYTICS_RENDERED_STR, @@ -15,7 +12,8 @@ import { ANALYTICS_SUBMIT_STR, ANALYTICS_UNFOCUS_STR, ANALYTICS_VALIDATION_ERROR_STR, - ANALYTICS_EXPRESS_PAGES_ARRAY + ANALYTICS_EXPRESS_PAGES_ARRAY, + ANALYTICS_EVENT } from './constants'; import { THREEDS2_ERROR, THREEDS2_FULL } from '../../components/ThreeDS2/constants'; import AdyenCheckoutError, { SDK_ERROR } from '../Errors/AdyenCheckoutError'; @@ -65,7 +63,7 @@ export const analyticsPreProcessor = (analyticsModule: AnalyticsModule) => { }; analyticsModule.createAnalyticsEvent({ - event: ANALYTICS_EVENT_INFO, + event: ANALYTICS_EVENT.info, data }); @@ -77,7 +75,7 @@ export const analyticsPreProcessor = (analyticsModule: AnalyticsModule) => { const data = { component, type, isStoredPaymentMethod, brand }; analyticsModule.createAnalyticsEvent({ - event: ANALYTICS_EVENT_INFO, + event: ANALYTICS_EVENT.info, data }); break; @@ -89,7 +87,7 @@ export const analyticsPreProcessor = (analyticsModule: AnalyticsModule) => { case ANALYTICS_INPUT_STR: // issuerList case ANALYTICS_DOWNLOAD_STR: // QR codes analyticsModule.createAnalyticsEvent({ - event: ANALYTICS_EVENT_INFO, + event: ANALYTICS_EVENT.info, data: { component, type, target } }); break; @@ -99,7 +97,7 @@ export const analyticsPreProcessor = (analyticsModule: AnalyticsModule) => { case ANALYTICS_SELECTED_STR: { const { issuer } = analyticsObj; analyticsModule.createAnalyticsEvent({ - event: ANALYTICS_EVENT_INFO, + event: ANALYTICS_EVENT.info, data: { component, type, target, issuer } }); break; @@ -108,7 +106,7 @@ export const analyticsPreProcessor = (analyticsModule: AnalyticsModule) => { case ANALYTICS_VALIDATION_ERROR_STR: { const { validationErrorCode, validationErrorMessage } = analyticsObj; analyticsModule.createAnalyticsEvent({ - event: ANALYTICS_EVENT_INFO, + event: ANALYTICS_EVENT.info, data: { component, type, target, validationErrorCode, validationErrorMessage } }); break; @@ -119,7 +117,7 @@ export const analyticsPreProcessor = (analyticsModule: AnalyticsModule) => { */ case ANALYTICS_SUBMIT_STR: analyticsModule.createAnalyticsEvent({ - event: ANALYTICS_EVENT_LOG, + event: ANALYTICS_EVENT.log, data: { component, type, message: 'Shopper clicked pay' } }); break; @@ -127,7 +125,7 @@ export const analyticsPreProcessor = (analyticsModule: AnalyticsModule) => { case ANALYTICS_ACTION_STR: { const { subtype, message } = analyticsObj; analyticsModule.createAnalyticsEvent({ - event: ANALYTICS_EVENT_LOG, + event: ANALYTICS_EVENT.log, data: { component, type, subtype, message } }); break; @@ -138,7 +136,7 @@ export const analyticsPreProcessor = (analyticsModule: AnalyticsModule) => { const { message, metadata, subtype, result } = analyticsObj; analyticsModule.createAnalyticsEvent({ - event: ANALYTICS_EVENT_LOG, + event: ANALYTICS_EVENT.log, data: { component, type, message, metadata, subtype, result } }); break; @@ -150,7 +148,7 @@ export const analyticsPreProcessor = (analyticsModule: AnalyticsModule) => { case THREEDS2_ERROR: { const { message, code, errorType } = analyticsObj; analyticsModule.createAnalyticsEvent({ - event: ANALYTICS_EVENT_ERROR, + event: ANALYTICS_EVENT.error, data: { component, type, message, code, errorType } }); break; diff --git a/packages/lib/src/core/Analytics/constants.ts b/packages/lib/src/core/Analytics/constants.ts index 8d64a39106..b805fe28d7 100644 --- a/packages/lib/src/core/Analytics/constants.ts +++ b/packages/lib/src/core/Analytics/constants.ts @@ -12,9 +12,23 @@ export const ANALYTICS_INFO_TIMER_INTERVAL = process.env.NODE_ENV === 'developme export const ANALYTICS_SEARCH_DEBOUNCE_TIME = 3000; -export const ANALYTICS_EVENT_LOG = 'log'; -export const ANALYTICS_EVENT_ERROR = 'error'; -export const ANALYTICS_EVENT_INFO = 'info'; +export const ANALYTICS_EVENT = { + log: 'log', + error: 'error', + info: 'info' +}; + +export const ANALYTICS_ERROR_TYPE = { + network: 'Network', + implementation: 'Implementation', + internal: 'Internal', + apiError: 'ApiError', + sdkError: 'SdkError', + thirdParty: 'ThirdParty', + generic: 'Generic', + redirect: 'Redirect', + threeDS2: 'ThreeDS2' +}; export const ANALYTICS_ACTION_STR = 'action'; export const ANALYTICS_SUBMIT_STR = 'submit'; @@ -39,11 +53,6 @@ export const ANALYTICS_FEATURED_ISSUER = 'featured_issuer'; export const ANALYTICS_LIST = 'list'; export const ANALYTICS_LIST_SEARCH = 'list_search'; -export const ANALYTICS_IMPLEMENTATION_ERROR = 'ImplementationError'; -export const ANALYTICS_API_ERROR = 'ApiError'; -export const ANALYTICS_SDK_ERROR = 'SdkError'; -export const ANALYTICS_NETWORK_ERROR = 'Network'; - export enum Analytics3DS2Errors { ACTION_IS_MISSING_PAYMENT_DATA = '700', // Missing 'paymentData' property from threeDS2 action ACTION_IS_MISSING_TOKEN = '701', // Missing 'token' property from threeDS2 action diff --git a/packages/lib/src/core/Analytics/types.ts b/packages/lib/src/core/Analytics/types.ts index 32e5408169..c318174232 100644 --- a/packages/lib/src/core/Analytics/types.ts +++ b/packages/lib/src/core/Analytics/types.ts @@ -1,6 +1,7 @@ import { PaymentAmount } from '../../types'; import { CoreConfiguration } from '../types'; import { SocialSecurityMode } from '../../components/Card/types'; +import { ANALYTICS_EVENT } from './constants'; export interface Experiment { controlGroup: boolean; @@ -85,9 +86,9 @@ export interface AnalyticsObject { configData?: Record; } -export type ANALYTICS_EVENT = 'log' | 'error' | 'info'; +export type AnalyticsEvent = (typeof ANALYTICS_EVENT)[keyof typeof ANALYTICS_EVENT]; -export type CreateAnalyticsObject = Omit & { event: ANALYTICS_EVENT }; +export type CreateAnalyticsObject = Omit & { event: AnalyticsEvent }; export type AnalyticsInitialEvent = { containerWidth: number; @@ -108,7 +109,7 @@ export type AnalyticsConfig = { export type CreateAnalyticsEventData = Omit; export type CreateAnalyticsEventObject = { - event: ANALYTICS_EVENT; + event: AnalyticsEvent; data: CreateAnalyticsEventData; };