@segment/analytics.js-integration-doubleclick-floodlight
Advanced tools
Comparing version 1.5.0 to 1.5.1
@@ -0,1 +1,8 @@ | ||
1.5.1 / 2020-04-16 | ||
================== | ||
* Adds support for top level `{{userId}}` proprety to be used as Custom Variable on Conversion Events. | ||
* Adds support for nested products propreties (ie. `products.$.price`) to be mapped in as a comma separated array on Conversion Events. | ||
* Adds support to use Transaction Method instead of Items Sold for `qty` if `useTransactionCounting` setting is enabled. | ||
1.5.0 / 2019-12-05 | ||
@@ -2,0 +9,0 @@ ================== |
@@ -23,2 +23,3 @@ 'use strict'; | ||
.option('segmentWriteKey', '') | ||
.option('useTransactionCounting', false) | ||
.tag( | ||
@@ -84,2 +85,3 @@ 'counter', | ||
} | ||
var settings = this.options; | ||
@@ -106,7 +108,23 @@ | ||
var segmentProp = variable.key.match(/{{(.*)}}/) || variable.key; | ||
if (variable.key.includes('$')) { | ||
segmentProp = variable.key.split('.$.'); | ||
} | ||
var segmentPropValue; | ||
if (Array.isArray(segmentProp)) { | ||
if (Array.isArray(segmentProp) && segmentProp[0] === 'products') { | ||
segmentProp = segmentProp.pop(); | ||
segmentPropValue = find(track.json(), segmentProp); | ||
var productPropArray = []; | ||
each(function(product) { | ||
if (product[segmentProp]) { | ||
productPropArray.push(product[segmentProp]); | ||
} | ||
}, track.products()); | ||
segmentPropValue = productPropArray.join(','); | ||
} else if (Array.isArray(segmentProp)) { | ||
segmentProp = segmentProp.pop(); | ||
if (segmentProp === 'userId') { | ||
segmentPropValue = self.analytics.user().id(); | ||
} else { | ||
segmentPropValue = find(track.json(), segmentProp); | ||
} | ||
} else { | ||
@@ -148,2 +166,4 @@ segmentPropValue = properties[segmentProp]; | ||
if (quantity) tagParams.qty = quantity; | ||
// overwrite qty param with 1 if customer is using Trasaction Counting mehtod instead of Items Sold method | ||
if (settings.useTransactionCounting) tagParams.qty = 1; | ||
// doubleclick wants revenue under this cost param, yes | ||
@@ -150,0 +170,0 @@ if (track.revenue()) tagParams.cost = track.revenue(); |
{ | ||
"name": "@segment/analytics.js-integration-doubleclick-floodlight", | ||
"description": "The DoubleClick Floodlight analytics.js integration.", | ||
"version": "1.5.0", | ||
"version": "1.5.1", | ||
"keywords": [ | ||
@@ -54,3 +54,3 @@ "analytics.js", | ||
}, | ||
"gitHead": "cbce1c61a1b51582d5826623a4535520f8dc7e53" | ||
"gitHead": "3bcebe008cc77ea43459c523b24768c0056a031a" | ||
} |
@@ -268,2 +268,196 @@ 'use strict'; | ||
it('should fire a floodlight sales tag properly with qty default to 1 when useTransactionCounting', function() { | ||
floodlight.options.useTransactionCounting = true; | ||
var properties = { | ||
checkout_id: 'fksdjfsdjfisjf9sdfjsd9f', | ||
order_id: '50314b8e9bcf000000000000', | ||
affiliation: 'Google Store', | ||
total: 30, | ||
revenue: 25, | ||
shipping: 3, | ||
tax: 2, | ||
discount: 2.5, | ||
coupon: 'hasbros', | ||
currency: 'USD', | ||
products: [ | ||
{ | ||
product_id: '507f1f77bcf86cd799439011', | ||
sku: '45790-32', | ||
name: 'Monopoly: 3rd Edition', | ||
price: 19, | ||
quantity: 1, | ||
category: 'Games' | ||
}, | ||
{ | ||
product_id: '505bd76785ebb509fc183733', | ||
sku: '46493-32', | ||
name: 'Uno Card Game', | ||
price: 3, | ||
quantity: 2, | ||
category: 'Games' | ||
} | ||
] | ||
}; | ||
var iframe = | ||
'<iframe src="https://' + | ||
options.source + | ||
'.fls.doubleclick.net/activityi' + | ||
';src=' + | ||
options.source + | ||
';type=' + | ||
options.events[1].value.type + | ||
';cat=' + | ||
options.events[1].value.cat + | ||
';qty=' + | ||
1 + | ||
';cost=' + | ||
properties.revenue + | ||
';dc_lat=;dc_rdid=;tag_for_child_directed_treatment=' + | ||
';ord=50314b8e9bcf000000000000?">'; | ||
analytics.track('Order Completed', properties); | ||
analytics.called(floodlight.load); | ||
analytics.loaded(iframe); | ||
}); | ||
it('should fire a floodlight sales tag properly with top level userId when identify previously triggered', function() { | ||
floodlight.options.events[3] = { | ||
key: 'Order Completed', | ||
value: { | ||
event: 'Order Completed', | ||
cat: 'activityTag', | ||
type: 'groupTag', | ||
customVariable: [ | ||
{ | ||
key: '{{userId}}', | ||
value: 'u8' | ||
} | ||
], | ||
isSalesTag: true, | ||
ordKey: 'orderId' | ||
} | ||
}; | ||
var properties = { | ||
checkout_id: 'fksdjfsdjfisjf9sdfjsd9f', | ||
order_id: '50314b8e9bcf000000000000', | ||
affiliation: 'Google Store', | ||
total: 30, | ||
revenue: 25, | ||
shipping: 3, | ||
tax: 2, | ||
discount: 2.5, | ||
coupon: 'hasbros', | ||
currency: 'USD', | ||
products: [ | ||
{ | ||
product_id: '507f1f77bcf86cd799439011', | ||
sku: '45790-32', | ||
name: 'Monopoly: 3rd Edition', | ||
price: 19, | ||
quantity: 1, | ||
category: 'Games' | ||
}, | ||
{ | ||
product_id: '505bd76785ebb509fc183733', | ||
sku: '46493-32', | ||
name: 'Uno Card Game', | ||
price: 3, | ||
quantity: 2, | ||
category: 'Games' | ||
} | ||
] | ||
}; | ||
var iframe = | ||
'<iframe src="https://' + | ||
options.source + | ||
'.fls.doubleclick.net/activityi' + | ||
';src=' + | ||
options.source + | ||
';type=' + | ||
options.events[1].value.type + | ||
';cat=' + | ||
options.events[1].value.cat + | ||
';qty=' + | ||
3 + | ||
';cost=' + | ||
properties.revenue + | ||
';dc_lat=;dc_rdid=;tag_for_child_directed_treatment=' + | ||
';ord=50314b8e9bcf000000000000;u8=some_previous_userId?">'; | ||
analytics.identify('some_previous_userId'); | ||
analytics.track('Order Completed', properties); | ||
analytics.called(floodlight.load); | ||
analytics.loaded(iframe); | ||
}); | ||
it('should fire a floodlight sales tag properly with product information', function() { | ||
floodlight.options.events[3] = { | ||
key: 'Order Completed', | ||
value: { | ||
event: 'Order Completed', | ||
cat: 'activityTag', | ||
type: 'groupTag', | ||
customVariable: [ | ||
{ | ||
key: 'products.$.category', | ||
value: 'u8' | ||
} | ||
], | ||
isSalesTag: true, | ||
ordKey: 'orderId' | ||
} | ||
}; | ||
var properties = { | ||
checkout_id: 'fksdjfsdjfisjf9sdfjsd9f', | ||
order_id: '50314b8e9bcf000000000000', | ||
affiliation: 'Google Store', | ||
total: 30, | ||
revenue: 25, | ||
shipping: 3, | ||
tax: 2, | ||
discount: 2.5, | ||
coupon: 'hasbros', | ||
currency: 'USD', | ||
products: [ | ||
{ | ||
product_id: '507f1f77bcf86cd799439011', | ||
sku: '45790-32', | ||
name: 'Monopoly: 3rd Edition', | ||
price: 19, | ||
quantity: 1, | ||
category: 'Games' | ||
}, | ||
{ | ||
product_id: '505bd76785ebb509fc183733', | ||
sku: '46493-32', | ||
name: 'Uno Card Game', | ||
price: 3, | ||
quantity: 2, | ||
category: 'Games' | ||
} | ||
] | ||
}; | ||
var iframe = | ||
'<iframe src="https://' + | ||
options.source + | ||
'.fls.doubleclick.net/activityi' + | ||
';src=' + | ||
options.source + | ||
';type=' + | ||
options.events[1].value.type + | ||
';cat=' + | ||
options.events[1].value.cat + | ||
';qty=' + | ||
3 + | ||
';cost=' + | ||
properties.revenue + | ||
';dc_lat=;dc_rdid=;tag_for_child_directed_treatment=' + | ||
';ord=50314b8e9bcf000000000000;u8=Games%2CGames?">'; | ||
analytics.identify('some_previous_userId'); | ||
analytics.track('Order Completed', properties); | ||
analytics.called(floodlight.load); | ||
analytics.loaded(iframe); | ||
}); | ||
it('should handle property lookups as custom variable keys', function() { | ||
@@ -270,0 +464,0 @@ var event = options.events[4]; |
29711
750