From 68a1bb406017f154a59b133baaf5d228d96b6c58 Mon Sep 17 00:00:00 2001 From: Sayan Das Date: Mon, 26 Sep 2022 21:32:05 +0530 Subject: [PATCH 1/3] Added messageId as eventId in Facebook Pixel --- integrations/facebook-pixel/lib/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integrations/facebook-pixel/lib/index.js b/integrations/facebook-pixel/lib/index.js index 62dbdc08f..83ed47e7b 100644 --- a/integrations/facebook-pixel/lib/index.js +++ b/integrations/facebook-pixel/lib/index.js @@ -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') }); }; /** From aa111458c3015da8c151133466c10920bec98dee Mon Sep 17 00:00:00 2001 From: Sayan Das Date: Tue, 27 Sep 2022 08:19:10 +0530 Subject: [PATCH 2/3] Bump facebook-pixel version --- integrations/facebook-pixel/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/facebook-pixel/package.json b/integrations/facebook-pixel/package.json index 8bd306b9b..0b3e0cbfe 100644 --- a/integrations/facebook-pixel/package.json +++ b/integrations/facebook-pixel/package.json @@ -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", From 2305b9e0626c0525eb9116e07df2f2cbf18542ca Mon Sep 17 00:00:00 2001 From: Gaurav Kochar Date: Tue, 29 Nov 2022 13:08:19 +0530 Subject: [PATCH 3/3] added a unit test case for page view event --- integrations/facebook-pixel/test/index.test.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/integrations/facebook-pixel/test/index.test.js b/integrations/facebook-pixel/test/index.test.js index 4e3a8c5c2..98d2e8a38 100644 --- a/integrations/facebook-pixel/test/index.test.js +++ b/integrations/facebook-pixel/test/index.test.js @@ -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; @@ -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); }); });