Skip to content

Commit e314632

Browse files
mericssonedubkendo
andauthored
DEST-1966 vero Order Completed Events "fan-out" (#454)
* Order Completed Events "fan-out" In order to make it easier to segment on individual product properties, order completed events will iterate over the array of products, sending one Ordered Product event for each product, as well as an Order Completed event. * Fix doc * Handles tags * increment package version Co-authored-by: Eric West <esw9999@gmail.com>
1 parent b6a6724 commit e314632

File tree

4 files changed

+205
-1
lines changed

4 files changed

+205
-1
lines changed

integrations/vero/HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2.2.0 / 2020-04-07
2+
==================
3+
4+
* Implement Order Completed Events "fan-out"
5+
16
2.1.0 / 2017-04-14
27
==================
38

integrations/vero/lib/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,29 @@ Vero.prototype.track = function(track) {
108108
if (tags) this.addOrRemoveTags(tags);
109109
};
110110

111+
/**
112+
* Order Completed.
113+
*
114+
* https://www.getvero.com/api/http/#actions
115+
* https://github.com/getvero/vero-api/blob/master/sections/js.md#tracking-events
116+
*
117+
* @api public
118+
* @param {Track} track
119+
*/
120+
121+
Vero.prototype.orderCompleted = function(track) {
122+
var products = track.properties().products;
123+
if (products && Array.isArray(products)) {
124+
for (var x = 0; x < products.length; x++) {
125+
push('track', 'Ordered Product', products[x], { source: 'segment' });
126+
}
127+
}
128+
129+
push('track', track.event(), track.properties(), { source: 'segment' });
130+
var tags = track.options('Vero').tags;
131+
if (tags) this.addOrRemoveTags(tags);
132+
};
133+
111134
/**
112135
* Alias.
113136
*

integrations/vero/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-vero",
33
"description": "The Vero analytics.js integration.",
4-
"version": "2.1.0",
4+
"version": "2.2.0",
55
"keywords": [
66
"analytics.js",
77
"analytics.js-integration",

integrations/vero/test/index.test.js

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,142 @@ describe('Vero', function() {
170170
analytics.track('unsubscribe', { id: 'id' });
171171
analytics.called(window._veroq.push, ['unsubscribe', { id: 'id' }]);
172172
});
173+
174+
it('should send order completed', function() {
175+
analytics.track('Order Completed', {
176+
order_id: '50314b8e9bcf000000000000',
177+
total: 30,
178+
revenue: 25,
179+
shipping: 3,
180+
tax: 2,
181+
discount: 2.5,
182+
coupon: 'foobar',
183+
currency: 'USD',
184+
products: [
185+
{
186+
product_id: '507f1f77bcf86cd799439011',
187+
sku: '45790-32',
188+
name: 'foobarbaz',
189+
price: 19,
190+
quantity: 1,
191+
category: 'foo',
192+
productUrl: 'http://www.example.com/path/to/product',
193+
imageUrl: 'http://www.example.com/path/to/product/image.png'
194+
},
195+
{
196+
product_id: '505bd76785ebb509fc183733',
197+
sku: '46493-32',
198+
name: 'barbazqux',
199+
price: 17.38,
200+
quantity: 2,
201+
category: 'bar'
202+
}
203+
]
204+
});
205+
analytics.called(window._veroq.push, [
206+
'track',
207+
'Order Completed',
208+
{
209+
order_id: '50314b8e9bcf000000000000',
210+
total: 30,
211+
revenue: 25,
212+
shipping: 3,
213+
tax: 2,
214+
discount: 2.5,
215+
coupon: 'foobar',
216+
currency: 'USD',
217+
products: [
218+
{
219+
product_id: '507f1f77bcf86cd799439011',
220+
sku: '45790-32',
221+
name: 'foobarbaz',
222+
price: 19,
223+
quantity: 1,
224+
category: 'foo',
225+
productUrl: 'http://www.example.com/path/to/product',
226+
imageUrl: 'http://www.example.com/path/to/product/image.png'
227+
},
228+
{
229+
product_id: '505bd76785ebb509fc183733',
230+
sku: '46493-32',
231+
name: 'barbazqux',
232+
price: 17.38,
233+
quantity: 2,
234+
category: 'bar'
235+
}
236+
]
237+
},
238+
{
239+
source: 'segment'
240+
}
241+
]);
242+
});
243+
244+
it('should send ordered product', function() {
245+
analytics.track('Order Completed', {
246+
order_id: '50314b8e9bcf000000000000',
247+
total: 30,
248+
revenue: 25,
249+
shipping: 3,
250+
tax: 2,
251+
discount: 2.5,
252+
coupon: 'foobar',
253+
currency: 'USD',
254+
products: [
255+
{
256+
product_id: '505bd76785ebb509fc183733',
257+
sku: '46493-32',
258+
name: 'barbazqux',
259+
price: 17.38,
260+
quantity: 2,
261+
category: 'bar'
262+
}
263+
]
264+
});
265+
analytics.calledTwice(window._veroq.push);
266+
analytics.called(window._veroq.push, [
267+
'track',
268+
'Order Completed',
269+
{
270+
order_id: '50314b8e9bcf000000000000',
271+
total: 30,
272+
revenue: 25,
273+
shipping: 3,
274+
tax: 2,
275+
discount: 2.5,
276+
coupon: 'foobar',
277+
currency: 'USD',
278+
products: [
279+
{
280+
product_id: '505bd76785ebb509fc183733',
281+
sku: '46493-32',
282+
name: 'barbazqux',
283+
price: 17.38,
284+
quantity: 2,
285+
category: 'bar'
286+
}
287+
]
288+
},
289+
{
290+
source: 'segment'
291+
}
292+
]);
293+
analytics.called(window._veroq.push, [
294+
'track',
295+
'Ordered Product',
296+
{
297+
product_id: '505bd76785ebb509fc183733',
298+
sku: '46493-32',
299+
name: 'barbazqux',
300+
price: 17.38,
301+
quantity: 2,
302+
category: 'bar'
303+
},
304+
{
305+
source: 'segment'
306+
}
307+
]);
308+
});
173309
});
174310

175311
describe('#alias', function() {
@@ -235,6 +371,46 @@ describe('Vero', function() {
235371
]);
236372
});
237373

374+
it('should work for Order Completed calls', function() {
375+
analytics.track(
376+
'Order Completed',
377+
{
378+
order_id: '50314b8e9bcf000000000000',
379+
total: 30,
380+
revenue: 25,
381+
shipping: 3,
382+
tax: 2,
383+
discount: 2.5,
384+
coupon: 'foobar',
385+
currency: 'USD',
386+
products: [
387+
{
388+
product_id: '505bd76785ebb509fc183733',
389+
sku: '46493-32',
390+
name: 'barbazqux',
391+
price: 17.38,
392+
quantity: 2,
393+
category: 'bar'
394+
}
395+
]
396+
},
397+
{
398+
integrations: {
399+
Vero: {
400+
tags: {
401+
action: 'add',
402+
values: ['yoloer']
403+
}
404+
}
405+
}
406+
}
407+
);
408+
analytics.assert.deepEqual(window._veroq.push.args[2][0], [
409+
'tags',
410+
{ add: ['yoloer'] }
411+
]);
412+
});
413+
238414
it('should work for .identify calls', function() {
239415
analytics.identify(
240416
'user-id',

0 commit comments

Comments
 (0)