Skip to content

Commit

Permalink
[MAIN] [STRATCONN-2841] Added event_id in page action of Pinterest Tag (
Browse files Browse the repository at this point in the history
#801)

* Added event_id in page action of pinterest tag

* typo fixed

* added check for page.properties

* re-arrange comments

* bump up pinterest tag from 1.2.4 to 1.2.5
  • Loading branch information
AnkitSegment authored Jun 3, 2024
1 parent dd3170e commit e09a394
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
26 changes: 19 additions & 7 deletions integrations/pinterest-tag/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

Expand Down
2 changes: 1 addition & 1 deletion integrations/pinterest-tag/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
16 changes: 15 additions & 1 deletion integrations/pinterest-tag/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,27 @@ 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-')) {
throw new Error('Expected eventId on window.pintrk Not found.');
}
});
});

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.');
}
});
});
});
});

0 comments on commit e09a394

Please sign in to comment.