Skip to content
This repository was archived by the owner on Dec 11, 2019. It is now read-only.

Commit 5a7c66a

Browse files
authored
Release 2.1.2
* maps monthlySpend to monthly_spend * maps revenue to price properly
1 parent a9ee2d2 commit 5a7c66a

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11

2+
2.1.2 / 2017-02-02
3+
==================
4+
5+
* Properly map monthlySpend and revenue for parity with server-side integration
6+
27
2.1.1 / 2016-09-13
38
==================
49

lib/index.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ Intercom.prototype.group = function(group) {
132132
// using .traits here since group.properties() doesn't take alias object
133133
var props = group.traits({
134134
createdAt: 'created',
135-
created: 'created_at'
135+
created: 'created_at',
136+
monthlySpend: 'monthly_spend'
136137
});
137138
props = convertDates(props, formatDate);
138139
var id = group.groupId();
@@ -151,7 +152,23 @@ Intercom.prototype.group = function(group) {
151152
*/
152153

153154
Intercom.prototype.track = function(track) {
154-
api('trackEvent', track.event(), track.properties());
155+
var props = track.properties();
156+
var revenue = track.revenue();
157+
if (revenue) {
158+
var revenueData = {
159+
// Intercom requests value in cents
160+
price: {
161+
amount: revenue * 100,
162+
currency: track.currency() // fallsback on 'USD'
163+
}
164+
};
165+
}
166+
167+
props = extend(props, revenueData);
168+
del(props, 'revenue');
169+
del(props, 'currency');
170+
171+
api('trackEvent', track.event(), props);
155172
};
156173

157174
/**

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-intercom",
33
"description": "The Intercom analytics.js integration.",
4-
"version": "2.1.1",
4+
"version": "2.1.2",
55
"keywords": [
66
"analytics.js",
77
"analytics.js-integration",

test/index.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,11 @@ describe('Intercom', function() {
302302
analytics.called(window.Intercom, 'update', { company: { id: 'id' } });
303303
});
304304

305+
it('should send map monthlySpend to monthly_spend', function() {
306+
analytics.group('id', { monthlySpend: 17.38 });
307+
analytics.called(window.Intercom, 'update', { company: { id: 'id', monthly_spend: 17.38 } });
308+
});
309+
305310
it('should send an id and properties', function() {
306311
analytics.group('id', { name: 'Name' });
307312
analytics.called(window.Intercom, 'update', {
@@ -348,6 +353,11 @@ describe('Intercom', function() {
348353
analytics.track('event');
349354
analytics.called(window.Intercom, 'trackEvent', 'event', {});
350355
});
356+
357+
it('should map price correctly', function() {
358+
analytics.track('event', { revenue: 200.00, currency: 50.00 });
359+
analytics.called(window.Intercom, 'trackEvent', 'event', { price: { amount: 20000, currency: 50.00 } });
360+
});
351361
});
352362

353363
describe('integration settings', function() {

0 commit comments

Comments
 (0)