Skip to content

Commit

Permalink
HGI 81 - Add event ID to page calls sent to FB Pixel for deduplication (
Browse files Browse the repository at this point in the history
#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]>
  • Loading branch information
sayan-das-in and Gaurav Kochar authored Dec 1, 2022
1 parent f8cc444 commit a5742fc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions integrations/facebook-pixel/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ FacebookPixel.prototype.loaded = function() {
* @param {Facade} identify
*/

FacebookPixel.prototype.page = function() {
window.fbq('track', 'PageView');
FacebookPixel.prototype.page = function(track) {
window.fbq('track', 'PageView', {}, { eventID: track.proxy('messageId') });
};

/**
Expand Down
2 changes: 1 addition & 1 deletion integrations/facebook-pixel/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@segment/analytics.js-integration-facebook-pixel",
"description": "The Facebook Pixel analytics.js integration.",
"version": "2.11.4",
"version": "2.11.5",
"keywords": [
"analytics.js",
"analytics.js-integration",
Expand Down
15 changes: 13 additions & 2 deletions integrations/facebook-pixel/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ function assertEventId(spy) {
throw new Error('Expected eventId on window.fbq.call. Not found.');
}
}
/**
* Event ID is generated automatically by Analytics.js, this function
* only checks that it was succesfully added as an 4th argument in PageView to a `window.fbq` call.
*/

function assertEventIdInPageView(spy) {
if (!spy.args[0][3].eventID.startsWith('ajs-')) {
throw new Error('Expected eventId on window.fbq.call. Not found.');
}
}

describe('Facebook Pixel', function() {
var analytics;
Expand Down Expand Up @@ -256,9 +266,10 @@ describe('Facebook Pixel', function() {
analytics.stub(window, 'fbq');
});

it('should track a pageview', function() {
it('should track a pageview along with eventID', function() {
analytics.page();
analytics.called(window.fbq, 'track', 'PageView');
analytics.called(window.fbq, 'track', 'PageView', {});
assertEventIdInPageView(window.fbq);
});
});

Expand Down

0 comments on commit a5742fc

Please sign in to comment.