diff --git a/integrations/pinterest-tag/lib/index.js b/integrations/pinterest-tag/lib/index.js index 2681efc6f..b3983d46f 100644 --- a/integrations/pinterest-tag/lib/index.js +++ b/integrations/pinterest-tag/lib/index.js @@ -62,16 +62,28 @@ Pinterest.prototype.identify = function(identify) { }; Pinterest.prototype.page = function(page) { + var pinterestPageProps = { + name: page.name() || '' + }; + + var eventKeys = ['event_id', 'eid', 'eventID']; + + for (var i = 0; i < eventKeys.length; i++) { + if (page.properties() && page.properties()[eventKeys[i]]) { + pinterestPageProps.event_id = page.properties()[eventKeys[i]]; + } + } + + if (this.options.mapMessageIdToEventId) { + pinterestPageProps.event_id = page.proxy('messageId'); + } + // If we have a category, the use ViewCategory. Otherwise, use a normal PageVisit. if (page.category()) { - window.pintrk('track', 'ViewCategory', { - category: page.category(), - name: page.name() || '' - }); + pinterestPageProps.category = page.category(); + window.pintrk('track', 'ViewCategory', pinterestPageProps); } else { - window.pintrk('track', 'PageVisit', { - name: page.name() || '' - }); + window.pintrk('track', 'PageVisit', pinterestPageProps); } }; diff --git a/integrations/pinterest-tag/package.json b/integrations/pinterest-tag/package.json index 70984d4a5..120066634 100644 --- a/integrations/pinterest-tag/package.json +++ b/integrations/pinterest-tag/package.json @@ -1,7 +1,7 @@ { "name": "@segment/analytics.js-integration-pinterest-tag", "description": "The Pinterest Tag analytics.js integration.", - "version": "1.2.4", + "version": "1.2.5", "keywords": [ "analytics.js", "analytics.js-integration", diff --git a/integrations/pinterest-tag/test/index.test.js b/integrations/pinterest-tag/test/index.test.js index 6d4929073..1264ce8ae 100644 --- a/integrations/pinterest-tag/test/index.test.js +++ b/integrations/pinterest-tag/test/index.test.js @@ -100,7 +100,7 @@ describe('Pinterest', function() { analytics.spy(window, 'pintrk'); }); - it('should set Segment messageId as Pinterest Evnet Id', function() { + it('should set Segment messageId as Pinterest Event Id', function() { analytics.track('Order Completed', {}); analytics.called(window.pintrk, 'track', 'Checkout'); if (!window.pintrk.args[0][2].event_id.startsWith('ajs-')) { @@ -108,5 +108,19 @@ describe('Pinterest', function() { } }); }); + + describe('#page', function() { + beforeEach(function() { + analytics.spy(window, 'pintrk'); + }); + + it('should set Segment messageId as Pinterest Event Id', function() { + analytics.page('PageVisit', {}); + analytics.called(window.pintrk, 'track', 'PageVisit'); + if (!window.pintrk.args[0][2].event_id.startsWith('ajs-')) { + throw new Error('Expected eventId on window.pintrk Not found.'); + } + }); + }); }); });