Skip to content

Commit a5742fc

Browse files
sayan-das-inGaurav Kochar
andauthored
HGI 81 - Add event ID to page calls sent to FB Pixel for deduplication (#701)
* Added messageId as eventId in Facebook Pixel * Bump facebook-pixel version * added a unit test case for page view event Co-authored-by: Gaurav Kochar <[email protected]>
1 parent f8cc444 commit a5742fc

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

integrations/facebook-pixel/lib/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ FacebookPixel.prototype.loaded = function() {
135135
* @param {Facade} identify
136136
*/
137137

138-
FacebookPixel.prototype.page = function() {
139-
window.fbq('track', 'PageView');
138+
FacebookPixel.prototype.page = function(track) {
139+
window.fbq('track', 'PageView', {}, { eventID: track.proxy('messageId') });
140140
};
141141

142142
/**

integrations/facebook-pixel/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@segment/analytics.js-integration-facebook-pixel",
33
"description": "The Facebook Pixel analytics.js integration.",
4-
"version": "2.11.4",
4+
"version": "2.11.5",
55
"keywords": [
66
"analytics.js",
77
"analytics.js-integration",

integrations/facebook-pixel/test/index.test.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ function assertEventId(spy) {
1414
throw new Error('Expected eventId on window.fbq.call. Not found.');
1515
}
1616
}
17+
/**
18+
* Event ID is generated automatically by Analytics.js, this function
19+
* only checks that it was succesfully added as an 4th argument in PageView to a `window.fbq` call.
20+
*/
21+
22+
function assertEventIdInPageView(spy) {
23+
if (!spy.args[0][3].eventID.startsWith('ajs-')) {
24+
throw new Error('Expected eventId on window.fbq.call. Not found.');
25+
}
26+
}
1727

1828
describe('Facebook Pixel', function() {
1929
var analytics;
@@ -256,9 +266,10 @@ describe('Facebook Pixel', function() {
256266
analytics.stub(window, 'fbq');
257267
});
258268

259-
it('should track a pageview', function() {
269+
it('should track a pageview along with eventID', function() {
260270
analytics.page();
261-
analytics.called(window.fbq, 'track', 'PageView');
271+
analytics.called(window.fbq, 'track', 'PageView', {});
272+
assertEventIdInPageView(window.fbq);
262273
});
263274
});
264275

0 commit comments

Comments
 (0)