Skip to content

Commit 9aa9216

Browse files
authored
Release 2.3.0
*Update value for Product Added and Product Viewed to take either properties.value or properties.price
1 parent c36db66 commit 9aa9216

File tree

4 files changed

+58
-7
lines changed

4 files changed

+58
-7
lines changed

HISTORY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2.3.0 / 2016-11-15
2+
==================
3+
4+
* Update value for Product Added and Product Viewed to take either properties.value or properties.price
15

26
2.2.1 / 2016-09-13
37
==================

lib/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var FacebookPixel = module.exports = integration('Facebook Pixel')
1919
.global('fbq')
2020
.option('pixelId', '')
2121
.option('agent', 'seg')
22+
.option('valueIdentifier', 'value')
2223
.option('initWithExistingTraits', false)
2324
.mapping('standardEvents')
2425
.mapping('legacyEvents')
@@ -159,7 +160,7 @@ FacebookPixel.prototype.productViewed = function(track) {
159160
content_name: track.name() || '',
160161
content_category: track.category() || '',
161162
currency: track.currency(),
162-
value: formatRevenue(track.price())
163+
value: this.options.valueIdentifier === 'value' ? formatRevenue(track.value()) : formatRevenue(track.price())
163164
});
164165

165166
// fall through for mapped legacy conversions
@@ -185,7 +186,7 @@ FacebookPixel.prototype.productAdded = function(track) {
185186
content_name: track.name() || '',
186187
content_category: track.category() || '',
187188
currency: track.currency(),
188-
value: formatRevenue(track.price())
189+
value: this.options.valueIdentifier === 'value' ? formatRevenue(track.value()) : formatRevenue(track.price())
189190
});
190191

191192
// fall through for mapped legacy conversions

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-facebook-pixel",
33
"description": "The Facebook Pixel analytics.js integration.",
4-
"version": "2.2.1",
4+
"version": "2.3.0",
55
"keywords": [
66
"analytics.js",
77
"analytics.js-integration",

test/index.test.js

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,11 @@ describe('Facebook Pixel', function() {
232232
product_id: '507f1f77bcf86cd799439011',
233233
currency: 'USD',
234234
quantity: 1,
235-
price: 24.75,
235+
price: 44.33,
236236
name: 'my product',
237237
category: 'cat 1',
238-
sku: 'p-298'
238+
sku: 'p-298',
239+
value: 24.75
239240
});
240241
analytics.called(window.fbq, 'track', 'ViewContent', {
241242
content_ids: ['507f1f77bcf86cd799439011'],
@@ -247,15 +248,38 @@ describe('Facebook Pixel', function() {
247248
});
248249
});
249250

251+
it('Should map properties.price to facebooks value if price is selected', function() {
252+
facebookPixel.options.valueIdentifier = 'price';
253+
analytics.track('Product Viewed', {
254+
product_id: '507f1f77bcf86cd799439011',
255+
currency: 'USD',
256+
quantity: 1,
257+
price: 44.33,
258+
name: 'my product',
259+
category: 'cat 1',
260+
sku: 'p-298',
261+
value: 24.75
262+
});
263+
analytics.called(window.fbq, 'track', 'ViewContent', {
264+
content_ids: ['507f1f77bcf86cd799439011'],
265+
content_type: 'product',
266+
content_name: 'my product',
267+
content_category: 'cat 1',
268+
currency: 'USD',
269+
value: '44.33'
270+
});
271+
});
272+
250273
it('Adding to Cart', function() {
251274
analytics.track('Product Added', {
252275
product_id: '507f1f77bcf86cd799439011',
253276
currency: 'USD',
254277
quantity: 1,
255-
price: 24.75,
278+
price: 44.33,
256279
name: 'my product',
257280
category: 'cat 1',
258-
sku: 'p-298'
281+
sku: 'p-298',
282+
value: 24.75
259283
});
260284
analytics.called(window.fbq, 'track', 'AddToCart', {
261285
content_ids: ['507f1f77bcf86cd799439011'],
@@ -267,6 +291,28 @@ describe('Facebook Pixel', function() {
267291
});
268292
});
269293

294+
it('Should map properties.price to facebooks value if price is selected', function() {
295+
facebookPixel.options.valueIdentifier = 'price';
296+
analytics.track('Product Added', {
297+
product_id: '507f1f77bcf86cd799439011',
298+
currency: 'USD',
299+
quantity: 1,
300+
price: 44.33,
301+
name: 'my product',
302+
category: 'cat 1',
303+
sku: 'p-298',
304+
value: 24.75
305+
});
306+
analytics.called(window.fbq, 'track', 'AddToCart', {
307+
content_ids: ['507f1f77bcf86cd799439011'],
308+
content_type: 'product',
309+
content_name: 'my product',
310+
content_category: 'cat 1',
311+
currency: 'USD',
312+
value: '44.33'
313+
});
314+
});
315+
270316
it('Completing an Order', function() {
271317
analytics.track('Order Completed', {
272318
products: [

0 commit comments

Comments
 (0)