Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we search for eid, eventID these specific attributes? How did we decide these three values?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@varadarajan-tw varadarajan-tw May 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. So, do we expect customers to provide these values in properties? Is this consistent with how we can handle track? Should we add supprot for eid, eventID in track as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, for track events, mappings are generated through the generatePropertiesObject function. Using forLoop, when the user adds any of these three event IDs, that value directly gets attached to the mappings.


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