From 23a0d6dcf5691daa5b275ea5597ec8af564ccf08 Mon Sep 17 00:00:00 2001 From: Sylvie Date: Wed, 22 May 2024 09:22:39 -0400 Subject: [PATCH] refactor(ec_plugin): add check only at the start --- src/plugins/ec.ts | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/plugins/ec.ts b/src/plugins/ec.ts index 2597771..ea17a40 100644 --- a/src/plugins/ec.ts +++ b/src/plugins/ec.ts @@ -135,31 +135,29 @@ export class ECPlugin extends BasePlugin { } private addECDataToPayload(eventType: string, payload: any) { - const isPageView = eventType === ECPluginEventTypes.pageview; + if (eventType === ECPluginEventTypes.pageview) { + return { + ...this.getLocationInformation(eventType, payload), + ...this.getDefaultContextInformation(eventType), + ...payload, + }; + } + const ecPayload = { ...this.getLocationInformation(eventType, payload), ...this.getDefaultContextInformation(eventType), - ...(isPageView - ? {} - : { - ...(this.action ? {action: this.action} : {}), - ...(this.actionData || {}), - }), + ...(this.action ? {action: this.action} : {}), + ...(this.actionData || {}), }; - const productAndImpressionPayload = isPageView - ? {} - : { - ...this.getProductPayload(), - ...this.getImpressionPayload(), - }; + const productPayload = this.getProductPayload(); + const impressionPayload = this.getImpressionPayload(); - if (!isPageView) { - this.clearData(); - } + this.clearData(); return { - ...productAndImpressionPayload, + ...productPayload, + ...impressionPayload, ...ecPayload, ...payload, };