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') }); }; /** 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", 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); }); });