Skip to content

Commit

Permalink
refactor(ec_plugin): add check only at the start
Browse files Browse the repository at this point in the history
  • Loading branch information
sallainCoveo committed May 22, 2024
1 parent cd38b20 commit 23a0d6d
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions src/plugins/ec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down

0 comments on commit 23a0d6d

Please sign in to comment.