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

Commit bac8a65

Browse files
author
Han
authored
Release 3.0.0
* remove any arrays or objects
1 parent 39da939 commit bac8a65

File tree

5 files changed

+31
-154
lines changed

5 files changed

+31
-154
lines changed

HISTORY.md

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

2+
3.0.0 / 2017-08-21
3+
==================
4+
5+
* Drop support for stringifying/flattened arrays or objects as requested by Intercom
6+
27
2.2.3 / 2017-02-16
38
==================
49

karma.conf.ci.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,6 @@ var customLaunchers = {
3333
browserName: 'safari',
3434
version: '9.0'
3535
},
36-
// FIXME(ndhoule): Bad IE7/8 support in testing packages make these fail
37-
// sl_ie_7: {
38-
// base: 'SauceLabs',
39-
// browserName: 'internet explorer',
40-
// version: '7'
41-
// },
42-
// sl_ie_8: {
43-
// base: 'SauceLabs',
44-
// browserName: 'internet explorer',
45-
// version: '8'
46-
// },
4736
sl_ie_9: {
4837
base: 'SauceLabs',
4938
browserName: 'internet explorer',

lib/index.js

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ var del = require('obj-case').del;
1010
var integration = require('@segment/analytics.js-integration');
1111
var is = require('is');
1212
var extend = require('@ndhoule/extend');
13-
var foldl = require('@ndhoule/foldl');
14-
var flatten = require('flat');
15-
var JSON = require('json3');
1613
var clone = require('@ndhoule/clone');
1714
var each = require('@ndhoule/each');
1815
var pick = require('@ndhoule/pick');
@@ -25,8 +22,6 @@ var Intercom = module.exports = integration('Intercom')
2522
.global('Intercom')
2623
.option('activator', '#IntercomDefaultWidget')
2724
.option('appId', '')
28-
.option('blacklisted', {})
29-
.option('defaultMethod', 'flatten')
3025
.option('richLinkProperties', [])
3126
.tag('<script src="https://widget.intercom.io/widget/{{ appId }}">');
3227

@@ -153,12 +148,12 @@ Intercom.prototype.group = function(group) {
153148
var id = group.groupId();
154149
if (id) props.id = id;
155150
var integrationSettings = group.options(this.name);
156-
151+
157152
// format nested custom traits
158153
props = formatNestedCustomTraits(props, settings);
159154

160155
var traits = extend({ company: props }, hideDefaultLauncher(integrationSettings));
161-
156+
162157
api('update', traits);
163158
};
164159

@@ -240,10 +235,8 @@ function formatDate(date) {
240235
* @return {Object} ret
241236
* @api private
242237
*/
243-
238+
244239
function formatNestedCustomTraits(obj, settings) {
245-
var blacklisted = settings.blacklisted || {};
246-
var defaultMethod = settings.defaultMethod || 'flatten';
247240
var richLinkProperties = settings.richLinkProperties;
248241
var basicIntercomTraits = [
249242
'companies',
@@ -277,42 +270,14 @@ function formatNestedCustomTraits(obj, settings) {
277270
// create object without custom traits to merge with formatted custom traits in the end
278271
var standardTraits = pick(semanticTraits, obj);
279272

280-
// handle custom nested traits according to the settings
281-
var formattedTraits = foldl(function(attrs, value, key) {
282-
var trait = blacklisted[key];
283-
284-
if (trait === 'stringify') {
285-
attrs.stringify[key] = value;
286-
} else if (trait === 'flatten') {
287-
attrs.flatten[key] = value;
288-
} else if (trait === 'drop') {
289-
return attrs;
290-
} else if (typeof value === 'object') {
291-
if (defaultMethod === 'stringify') attrs.stringify[key] = value;
292-
if (defaultMethod === 'flatten') attrs.flatten[key] = value;
293-
if (defaultMethod === 'drop') return attrs;
294-
} else {
295-
attrs.nonNestedTraits[key] = value;
296-
}
297-
return attrs;
298-
}, { flatten: {}, stringify: {}, nonNestedTraits: {} }, customTraits);
299-
300-
// stringify specified traits
301-
var stringifiedTraits = foldl(function(ret, value, key) {
302-
ret[key] = JSON.stringify(value);
303-
return ret;
304-
}, {}, formattedTraits.stringify);
305-
306-
// flatten specified traits
307-
var flattenedTraits = foldl(function(ret, value, key) {
308-
var pair = {};
309-
pair[key] = value;
310-
ret = extend(flatten(pair), ret);
311-
return ret;
312-
}, {}, formattedTraits.flatten);
273+
// drop any arrays or objects
274+
var supportedTraits = {};
275+
each(function(value, key) {
276+
if (!is.object(value) && !is.array(value)) supportedTraits[key] = value;
277+
}, customTraits);
313278

314279
// combine all the traits
315-
return extend(standardTraits, stringifiedTraits, flattenedTraits, formattedTraits.nonNestedTraits);
280+
return extend(supportedTraits, standardTraits);
316281
}
317282

318283
/**

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.2.3",
4+
"version": "3.0.0",
55
"keywords": [
66
"analytics.js",
77
"analytics.js-integration",

test/index.test.js

Lines changed: 16 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ describe('Intercom', function() {
4141
.global('Intercom')
4242
.option('activator', '#IntercomDefaultWidget')
4343
.option('appId', '')
44-
.option('blacklisted', {})
45-
.option('defaultMethod', 'flatten')
4644
.option('richLinkProperties', [])
4745
.tag('<script src="https://widget.intercom.io/widget/{{ appId }}">'));
4846
});
@@ -173,7 +171,7 @@ describe('Intercom', function() {
173171
});
174172
});
175173

176-
it('should selectively stringify, flatten, or drop traits', function() {
174+
it('should drop arrays or objects in traits', function() {
177175
analytics.identify('id', {
178176
dropMe: { foo: 'bar', ahoy: { okay: 'hello' } },
179177
stringifyMe: [{ a: 'b' }],
@@ -182,82 +180,6 @@ describe('Intercom', function() {
182180
analytics.called(window.Intercom, 'boot', {
183181
app_id: options.appId,
184182
user_id: 'id',
185-
stringifyMe: '[{\"a\":\"b\"}]',
186-
'flattenMe.pizza': 'cheese',
187-
'flattenMe.spongebob.patrick': 'star',
188-
id: 'id'
189-
});
190-
});
191-
192-
it('should let you set flatten as a default method for handling nested objects', function() {
193-
intercom.options.defaultMethod = 'flatten';
194-
195-
analytics.identify('id', {
196-
dropMe: { foo: 'bar', ahoy: { okay: 'hello' } },
197-
stringifyMe: [{ a: 'b' }],
198-
flattenMe: { pizza: 'cheese', spongebob: { patrick: 'star' } },
199-
array: ['food', { nom: 'avocados' } ],
200-
song: 'Starboy',
201-
artist: { singer: 'the weekend', beats: 'daft punk' }
202-
});
203-
analytics.called(window.Intercom, 'boot', {
204-
app_id: options.appId,
205-
user_id: 'id',
206-
stringifyMe: '[{\"a\":\"b\"}]',
207-
'flattenMe.pizza': 'cheese',
208-
'flattenMe.spongebob.patrick': 'star',
209-
song: 'Starboy',
210-
'artist.singer': 'the weekend',
211-
'artist.beats': 'daft punk',
212-
'array.0': 'food',
213-
'array.1.nom': 'avocados',
214-
id: 'id'
215-
});
216-
});
217-
218-
it('should let you set stringify as a default method for handling nested objects', function() {
219-
intercom.options.defaultMethod = 'stringify';
220-
221-
analytics.identify('id', {
222-
dropMe: { foo: 'bar', ahoy: { okay: 'hello' } },
223-
stringifyMe: [{ a: 'b' }],
224-
flattenMe: { pizza: 'cheese', spongebob: { patrick: 'star' } },
225-
array: ['food', { nom: 'avocados' } ],
226-
song: 'Starboy',
227-
artist: { singer: 'the weekend', beats: 'daft punk' }
228-
});
229-
analytics.called(window.Intercom, 'boot', {
230-
app_id: options.appId,
231-
user_id: 'id',
232-
stringifyMe: '[{\"a\":\"b\"}]',
233-
'flattenMe.pizza': 'cheese',
234-
'flattenMe.spongebob.patrick': 'star',
235-
song: 'Starboy',
236-
array: '[\"food\",{\"nom\":\"avocados\"}]',
237-
artist: '{\"singer\":\"the weekend\",\"beats\":\"daft punk\"}',
238-
id: 'id'
239-
});
240-
});
241-
242-
243-
it('should let you set drop as a default method for handling nested objects', function() {
244-
intercom.options.defaultMethod = 'drop';
245-
246-
analytics.identify('id', {
247-
dropMe: { foo: 'bar', ahoy: { okay: 'hello' } },
248-
stringifyMe: [{ a: 'b' }],
249-
flattenMe: { pizza: 'cheese', spongebob: { patrick: 'star' } },
250-
array: ['food', { nom: 'avocados' } ],
251-
song: 'Starboy',
252-
artist: { singer: 'the weekend', beats: 'daft punk' }
253-
});
254-
analytics.called(window.Intercom, 'boot', {
255-
app_id: options.appId,
256-
user_id: 'id',
257-
stringifyMe: '[{\"a\":\"b\"}]',
258-
'flattenMe.pizza': 'cheese',
259-
'flattenMe.spongebob.patrick': 'star',
260-
song: 'Starboy',
261183
id: 'id'
262184
});
263185
});
@@ -457,22 +379,19 @@ describe('Intercom', function() {
457379
analytics.called(window.Intercom, 'update', {
458380
company: {
459381
album: 'Starboy',
460-
id: 'id'
382+
id: 'id'
461383
}
462384
});
463385
});
464386

465-
it('should selectively stringify, flatten, or drop traits', function() {
387+
it('should drop arrays or objects in traits', function() {
466388
analytics.group('id', {
467389
dropMe: { foo: 'bar', ahoy: { okay: 'hello' } },
468390
stringifyMe: [{ a: 'b' }],
469391
flattenMe: { pizza: 'cheese', spongebob: { patrick: 'star' } }
470392
});
471-
analytics.called(window.Intercom, 'update', {
393+
analytics.called(window.Intercom, 'update', {
472394
company: {
473-
stringifyMe: '[{\"a\":\"b\"}]',
474-
'flattenMe.pizza': 'cheese',
475-
'flattenMe.spongebob.patrick': 'star',
476395
id: 'id'
477396
}
478397
});
@@ -501,23 +420,22 @@ describe('Intercom', function() {
501420
});
502421
});
503422

504-
it('should selectively stringify, flatten, or drop traits', function() {
423+
it('should drop arrays or objects in properties', function() {
505424
analytics.track('event', {
506425
dropMe: { foo: 'bar', ahoy: { okay: 'hello' } },
507426
stringifyMe: [{ a: 'b' }],
508-
flattenMe: { pizza: 'cheese', spongebob: { patrick: 'star' } }
427+
flattenMe: { pizza: 'cheese', spongebob: { patrick: 'star' } },
428+
suh: 'dude'
509429
});
510-
analytics.called(window.Intercom, 'trackEvent', 'event', {
511-
stringifyMe: '[{\"a\":\"b\"}]',
512-
'flattenMe.pizza': 'cheese',
513-
'flattenMe.spongebob.patrick': 'star'
430+
analytics.called(window.Intercom, 'trackEvent', 'event', {
431+
suh: 'dude'
514432
});
515433
});
516434

517435
it('should send Rich Link as nested object', function() {
518436
intercom.options.richLinkProperties = ['article', 'orderNumber'];
519437

520-
analytics.track('event', {
438+
analytics.track('event', {
521439
article: {
522440
url: 'www.suh.com',
523441
value: 'suh dude'
@@ -539,18 +457,18 @@ describe('Intercom', function() {
539457

540458
it('page: should set hide_default_launcher if integration setting exists for it', function() {
541459
var integrationSettings = {
542-
Intercom: { hideDefaultLauncher: true }
460+
Intercom: { hideDefaultLauncher: true }
543461
};
544462
analytics.page({}, integrationSettings);
545463
analytics.called(window.Intercom, 'boot', {
546464
app_id: options.appId,
547465
hide_default_launcher: true
548466
});
549-
});
467+
});
550468

551469
it('identify: should set hide_default_launcher if integration setting exists for it', function() {
552470
var integrationSettings = {
553-
Intercom: { hideDefaultLauncher: true }
471+
Intercom: { hideDefaultLauncher: true }
554472
};
555473
analytics.identify('id', {}, integrationSettings);
556474
analytics.called(window.Intercom, 'boot', {
@@ -559,18 +477,18 @@ describe('Intercom', function() {
559477
id: 'id',
560478
hide_default_launcher: true
561479
});
562-
});
480+
});
563481

564482
it('group: should set hide_default_launcher if integration setting exists for it', function() {
565483
var integrationSettings = {
566-
Intercom: { hideDefaultLauncher: true }
484+
Intercom: { hideDefaultLauncher: true }
567485
};
568486
analytics.group('id', {}, integrationSettings);
569487
analytics.called(window.Intercom, 'update', {
570488
company: { id: 'id' },
571489
hide_default_launcher: true
572490
});
573-
});
491+
});
574492
});
575493
});
576494
});

0 commit comments

Comments
 (0)