Skip to content

Commit e09a394

Browse files
authored
[MAIN] [STRATCONN-2841] Added event_id in page action of Pinterest Tag (#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
1 parent dd3170e commit e09a394

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

integrations/pinterest-tag/lib/index.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,28 @@ Pinterest.prototype.identify = function(identify) {
6262
};
6363

6464
Pinterest.prototype.page = function(page) {
65+
var pinterestPageProps = {
66+
name: page.name() || ''
67+
};
68+
69+
var eventKeys = ['event_id', 'eid', 'eventID'];
70+
71+
for (var i = 0; i < eventKeys.length; i++) {
72+
if (page.properties() && page.properties()[eventKeys[i]]) {
73+
pinterestPageProps.event_id = page.properties()[eventKeys[i]];
74+
}
75+
}
76+
77+
if (this.options.mapMessageIdToEventId) {
78+
pinterestPageProps.event_id = page.proxy('messageId');
79+
}
80+
6581
// If we have a category, the use ViewCategory. Otherwise, use a normal PageVisit.
6682
if (page.category()) {
67-
window.pintrk('track', 'ViewCategory', {
68-
category: page.category(),
69-
name: page.name() || ''
70-
});
83+
pinterestPageProps.category = page.category();
84+
window.pintrk('track', 'ViewCategory', pinterestPageProps);
7185
} else {
72-
window.pintrk('track', 'PageVisit', {
73-
name: page.name() || ''
74-
});
86+
window.pintrk('track', 'PageVisit', pinterestPageProps);
7587
}
7688
};
7789

integrations/pinterest-tag/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@segment/analytics.js-integration-pinterest-tag",
33
"description": "The Pinterest Tag analytics.js integration.",
4-
"version": "1.2.4",
4+
"version": "1.2.5",
55
"keywords": [
66
"analytics.js",
77
"analytics.js-integration",

integrations/pinterest-tag/test/index.test.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,27 @@ describe('Pinterest', function() {
100100
analytics.spy(window, 'pintrk');
101101
});
102102

103-
it('should set Segment messageId as Pinterest Evnet Id', function() {
103+
it('should set Segment messageId as Pinterest Event Id', function() {
104104
analytics.track('Order Completed', {});
105105
analytics.called(window.pintrk, 'track', 'Checkout');
106106
if (!window.pintrk.args[0][2].event_id.startsWith('ajs-')) {
107107
throw new Error('Expected eventId on window.pintrk Not found.');
108108
}
109109
});
110110
});
111+
112+
describe('#page', function() {
113+
beforeEach(function() {
114+
analytics.spy(window, 'pintrk');
115+
});
116+
117+
it('should set Segment messageId as Pinterest Event Id', function() {
118+
analytics.page('PageVisit', {});
119+
analytics.called(window.pintrk, 'track', 'PageVisit');
120+
if (!window.pintrk.args[0][2].event_id.startsWith('ajs-')) {
121+
throw new Error('Expected eventId on window.pintrk Not found.');
122+
}
123+
});
124+
});
111125
});
112126
});

0 commit comments

Comments
 (0)