Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement(Integration): Pinterest Tag event_id added for deduplication + custom event support #635

Merged
merged 4 commits into from
Sep 5, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions integrations/PinterestTag/browser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable class-methods-use-this */
import get from "get-value";
import logger from "../../utils/logUtil";
import {
eventMapping,
Expand All @@ -23,6 +24,7 @@ export default class PinterestTag {
this.customProperties = config.customProperties || [];
this.userDefinedEventsMapping = config.eventsMapping || [];
this.name = NAME;
this.deduplicationKey = config.deduplicationKey;
logger.debug("config", config);
}

Expand Down Expand Up @@ -174,15 +176,12 @@ export default class PinterestTag {
/**
* This gives destination events .
* Logics: If our eventMapping is not able to map the event that is sent by user payload then it will look into
* userDefinedEventsMapping array. In case if it is not found there as well, it will return undefined.
* userDefinedEventsMapping array. In case if it is not found there as well, it will return "custom".
* @param {rudder event name} event
* @returns
*/
getDestinationEventName(event) {
const destinationEvent = eventMapping.find((p) =>
p.src.includes(event.toLowerCase())
);
if (!destinationEvent && this.userDefinedEventsMapping.length > 0) {
if (this.userDefinedEventsMapping.length > 0) {
const userDefinedEvent = this.userDefinedEventsMapping.find(
(e) => e.from.toLowerCase() === event.toLowerCase()
);
Expand All @@ -193,14 +192,23 @@ export default class PinterestTag {
};
}
}
const destinationEvent = eventMapping.find((p) =>
p.src.includes(event.toLowerCase())
);
if (!destinationEvent) {
return {
dest: "custom",
};
utsabc marked this conversation as resolved.
Show resolved Hide resolved
}
return destinationEvent;
}

track(rudderElement) {
if (!rudderElement.message || !rudderElement.message.event) {
return;
}
const { properties, event } = rudderElement.message;
const { message } = rudderElement;
const { properties, event, messageId } = message;
let eventName = event;
const destEvent = this.getDestinationEventName(event);
if (isDefinedAndNotNull(destEvent)) {
Expand All @@ -211,6 +219,8 @@ export default class PinterestTag {
destEvent?.hasEmptyProducts,
destEvent?.isUserDefinedEvent
);
pinterestObject.event_id =
get(message, `${this.deduplicationKey}`) || messageId;

this.sendPinterestTrack(eventName, pinterestObject);
}
Expand Down