Skip to content

Commit 4855d8c

Browse files
authored
Merge pull request #23 from segment-integrations/ecom-specv2
support ecom-specv2
2 parents 15ee0c5 + 328c80a commit 4855d8c

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

lib/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var foldl = require('@ndhoule/foldl');
99
var each = require('@ndhoule/each');
1010
var reject = require('reject');
1111
var dateformat = require('dateformat');
12+
var Track = require('segmentio-facade').Track;
1213

1314
/**
1415
* Expose `Facebook Pixel`.
@@ -151,7 +152,7 @@ FacebookPixel.prototype.productListViewed = function(track) {
151152

152153
FacebookPixel.prototype.productViewed = function(track) {
153154
window.fbq('track', 'ViewContent', {
154-
content_ids: [track.id() || track.sku() || ''],
155+
content_ids: [track.productId() || track.id() || track.sku() || ''],
155156
content_type: 'product',
156157
content_name: track.name() || '',
157158
content_category: track.category() || '',
@@ -177,7 +178,7 @@ FacebookPixel.prototype.productViewed = function(track) {
177178

178179
FacebookPixel.prototype.productAdded = function(track) {
179180
window.fbq('track', 'AddToCart', {
180-
content_ids: [track.id() || track.sku() || ''],
181+
content_ids: [track.productId() || track.id() || track.sku() || ''],
181182
content_type: 'product',
182183
content_name: track.name() || '',
183184
content_category: track.category() || '',
@@ -202,9 +203,9 @@ FacebookPixel.prototype.productAdded = function(track) {
202203
*/
203204

204205
FacebookPixel.prototype.orderCompleted = function(track) {
205-
var key;
206206
var content_ids = foldl(function(acc, product) {
207-
key = product.id || product.sku;
207+
var item = new Track({ properties: product });
208+
var key = item.productId() || item.id() || item.sku();
208209
if (key) acc.push(key);
209210
return acc;
210211
}, [], track.products() || []);

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"@ndhoule/foldl": "^2.0.1",
2828
"@segment/analytics.js-integration": "^3.1.0",
2929
"dateformat": "^1.0.12",
30-
"reject": "0.0.1"
30+
"reject": "0.0.1",
31+
"segmentio-facade": "^3.1.0"
3132
},
3233
"devDependencies": {
3334
"@segment/analytics.js-core": "^3.0.0",

test/index.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ describe('Facebook Pixel', function() {
216216

217217
it('Product Viewed', function() {
218218
analytics.track('Product Viewed', {
219-
id: '507f1f77bcf86cd799439011',
219+
product_id: '507f1f77bcf86cd799439011',
220220
currency: 'USD',
221221
quantity: 1,
222222
price: 24.75,
@@ -236,7 +236,7 @@ describe('Facebook Pixel', function() {
236236

237237
it('Adding to Cart', function() {
238238
analytics.track('Product Added', {
239-
id: '507f1f77bcf86cd799439011',
239+
product_id: '507f1f77bcf86cd799439011',
240240
currency: 'USD',
241241
quantity: 1,
242242
price: 24.75,
@@ -257,8 +257,8 @@ describe('Facebook Pixel', function() {
257257
it('Completing an Order', function() {
258258
analytics.track('Order Completed', {
259259
products: [
260-
{ id: '507f1f77bcf86cd799439011' },
261-
{ id: '505bd76785ebb509fc183733' }
260+
{ product_id: '507f1f77bcf86cd799439011' },
261+
{ product_id: '505bd76785ebb509fc183733' }
262262
],
263263
currency: 'USD',
264264
total: 0.50
@@ -275,8 +275,8 @@ describe('Facebook Pixel', function() {
275275
facebookPixel.options.legacyEvents = { 'Completed Order': '123456' };
276276
analytics.track('Completed Order', {
277277
products: [
278-
{ id: '507f1f77bcf86cd799439011' },
279-
{ id: '505bd76785ebb509fc183733' }
278+
{ product_id: '507f1f77bcf86cd799439011' },
279+
{ product_id: '505bd76785ebb509fc183733' }
280280
],
281281
currency: 'USD',
282282
total: 0.50

0 commit comments

Comments
 (0)