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

Facebook Pixel event_id discrepancy #486

Merged
merged 6 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
36 changes: 19 additions & 17 deletions integrations/FacebookPixel/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import each from "@ndhoule/each";
import sha256 from "crypto-js/sha256";
import ScriptLoader from "../ScriptLoader";
import logger from "../../utils/logUtil";
import getEventId from "./utils";
import { getHashFromArray } from "../utils/commonUtils";
import { NAME, traitsMapper } from "./constants";
import { constructPayload } from "../../utils/utils";
Expand Down Expand Up @@ -72,8 +73,8 @@ class FacebookPixel {
}

page(rudderElement) {
const { properties, messageId } = rudderElement.message;
window.fbq("track", "PageView", properties, { eventID: messageId });
const { properties } = rudderElement.message;
window.fbq("track", "PageView", properties, { event_id: getEventId(rudderElement.message) });
}

identify(rudderElement) {
Expand Down Expand Up @@ -156,6 +157,7 @@ class FacebookPixel {
query = properties.query;
}
const customProperties = this.buildPayLoad(rudderElement, true);
const eventID = getEventId(rudderElement.message);
if (event === "Product List Viewed") {
let contentType;
const contentIds = [];
Expand Down Expand Up @@ -199,7 +201,7 @@ class FacebookPixel {
customProperties
),
{
eventID: messageId,
event_id: eventID,
}
);
each((val, key) => {
Expand All @@ -213,7 +215,7 @@ class FacebookPixel {
value: revValue,
},
{
eventID: messageId,
event_id: eventID,
}
);
}
Expand Down Expand Up @@ -244,7 +246,7 @@ class FacebookPixel {
customProperties
),
{
eventID: messageId,
event_id: eventID,
}
);

Expand All @@ -261,7 +263,7 @@ class FacebookPixel {
: this.formatRevenue(price),
},
{
eventID: messageId,
event_id: eventID,
}
);
}
Expand Down Expand Up @@ -293,7 +295,7 @@ class FacebookPixel {
customProperties
),
{
eventID: messageId,
event_id: eventID,
}
);

Expand All @@ -310,7 +312,7 @@ class FacebookPixel {
: this.formatRevenue(price),
},
{
eventID: messageId,
event_id: eventID,
}
);
}
Expand Down Expand Up @@ -369,7 +371,7 @@ class FacebookPixel {
customProperties
),
{
eventID: messageId,
event_id: eventID,
}
);

Expand All @@ -384,7 +386,7 @@ class FacebookPixel {
value: revValue,
},
{
eventID: messageId,
event_id: eventID,
}
);
}
Expand All @@ -404,7 +406,7 @@ class FacebookPixel {
customProperties
),
{
eventID: messageId,
event_id: eventID,
}
);

Expand All @@ -419,7 +421,7 @@ class FacebookPixel {
value: revValue,
},
{
eventID: messageId,
event_id: eventID,
}
);
}
Expand Down Expand Up @@ -464,7 +466,7 @@ class FacebookPixel {
customProperties
),
{
eventID: messageId,
event_id: eventID,
}
);

Expand All @@ -479,7 +481,7 @@ class FacebookPixel {
value: revValue,
},
{
eventID: messageId,
event_id: eventID,
}
);
}
Expand All @@ -494,15 +496,15 @@ class FacebookPixel {
const payloadVal = this.buildPayLoad(rudderElement, false);
payloadVal.value = revValue;
window.fbq("trackSingleCustom", self.pixelId, event, payloadVal, {
eventID: messageId,
event_id: eventID,
});
} else {
each((val, key) => {
if (key === event.toLowerCase()) {
payload.currency = currVal;

window.fbq("trackSingle", self.pixelId, val, payload, {
eventID: messageId,
event_id: eventID,
});
}
}, standardTo);
Expand All @@ -518,7 +520,7 @@ class FacebookPixel {
value: revValue,
},
{
eventID: messageId,
event_id: eventID,
}
);
}
Expand Down
4 changes: 4 additions & 0 deletions integrations/FacebookPixel/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function getEventId(message){
return message.traits.event_id || message.context.traits.event_id || message.properties.event_id || message.messageId;
};
export default getEventId;