Skip to content

Commit a441a1f

Browse files
gpsamsonmericsson
andauthored
[STRATCONN-588] Generate bundledConfigIds (#555)
* Spike intersection of bundled and maybeBundledConfigIds * Update test cases and short-circuit when maybeBundledConfigIds falsy * Fix bad loop + Add test * Update segmentio version to 4.4.1 * Update metadata ordering Co-authored-by: Marcus Ericsson <36717+mericsson@users.noreply.github.com> * Fix version number * Rename bundledConfigIds + Remove unbundledConfigIds Co-authored-by: Marcus Ericsson <36717+mericsson@users.noreply.github.com>
1 parent cf75105 commit a441a1f

File tree

4 files changed

+66
-7
lines changed

4 files changed

+66
-7
lines changed

integrations/segmentio/HISTORY.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
4.4.0 / 2020-02-05
2+
==================
3+
4+
* Removes the `bundledConfigIds` _setting_ and instead generates `bundledConfigIds` using the intersection
5+
of `bundled` destinations and the new `maybeBundledConfigIds` setting. `bundledConfigIds` and `unbundledConfigIds`
6+
is still appended to event metadata. This change is meant to ensure that `bundledConfigIds` only includes the
7+
subset of destinations that is generated at runtime for the `bundled` array.
8+
* Fixes the use of `const` from a previous release.
9+
110
4.3.0 / 2020-01-13
211
==================
312

integrations/segmentio/lib/index.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var utm = require('@segment/utm-params');
1818
var uuid = require('@lukeed/uuid').v4;
1919
var Queue = require('@segment/localstorage-retry');
2020

21-
const json = JSON;
21+
var json = JSON;
2222

2323
/**
2424
* Cookie options
@@ -64,7 +64,9 @@ var Segment = (exports = module.exports = integration('Segment.io')
6464
.option('saveCrossDomainIdInLocalStorage', true)
6565
.option('retryQueue', true)
6666
.option('addBundledMetadata', false)
67-
.option('unbundledIntegrations', []));
67+
.option('unbundledIntegrations', []))
68+
.option('unbundledConfigIds', [])
69+
.option('maybeBundledConfigIds', {});
6870

6971
/**
7072
* Get the store.
@@ -315,11 +317,31 @@ Segment.prototype.normalize = function(message) {
315317
}
316318
if (this.options.addBundledMetadata) {
317319
var bundled = keys(this.analytics.Integrations);
320+
var maybeBundledConfigIds = this.options.maybeBundledConfigIds
321+
322+
// Generate a list of bundled config IDs using the intersection of
323+
// bundled destination names and maybe bundled config IDs.
324+
var bundledConfigIds = []
325+
for (var i = 0; i < bundled.length; i++) {
326+
var name = bundled[i]
327+
if (!maybeBundledConfigIds) {
328+
break
329+
}
330+
if (!maybeBundledConfigIds[name]) {
331+
continue
332+
}
333+
334+
for (var j = 0; j < maybeBundledConfigIds[name].length; j++) {
335+
var id = maybeBundledConfigIds[name][j]
336+
bundledConfigIds.push(id)
337+
}
338+
}
339+
340+
318341
msg._metadata = msg._metadata || {};
319342
msg._metadata.bundled = bundled;
320343
msg._metadata.unbundled = this.options.unbundledIntegrations;
321-
msg._metadata.bundledConfigIds = this.options.bundledConfigIds;
322-
msg._metadata.unbundledConfigIds = this.options.unbundledConfigIds;
344+
msg._metadata.bundledIds = bundledConfigIds;
323345
}
324346
this.debug('normalized %o', msg);
325347
this.ampId(ctx);

integrations/segmentio/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-segmentio",
33
"description": "The Segmentio analytics.js integration.",
4-
"version": "4.3.1",
4+
"version": "4.4.0",
55
"keywords": [
66
"analytics.js",
77
"analytics.js-integration",

integrations/segmentio/test/index.test.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,9 @@ describe('Segment.io', function() {
449449
segment = new Segment(options);
450450
ajs.use(Segment);
451451
ajs.use(integration('other'));
452+
ajs.use(integration('another'));
452453
ajs.add(segment);
453-
ajs.initialize({ other: {} });
454+
ajs.initialize({ other: {}, another: {} });
454455
});
455456

456457
it('should add a list of bundled integrations when `addBundledMetadata` is set', function() {
@@ -459,7 +460,7 @@ describe('Segment.io', function() {
459460

460461
assert(object);
461462
assert(object._metadata);
462-
assert.deepEqual(object._metadata.bundled, ['Segment.io', 'other']);
463+
assert.deepEqual(object._metadata.bundled, ['Segment.io', 'other', 'another']);
463464
});
464465

465466
it('should add a list of unbundled integrations when `addBundledMetadata` and `unbundledIntegrations` are set', function() {
@@ -478,6 +479,33 @@ describe('Segment.io', function() {
478479
assert(object);
479480
assert(!object._metadata);
480481
});
482+
483+
it('should generate and add a list of bundled destination config ids when `addBundledMetadata` is set', function() {
484+
segment.options.addBundledMetadata = true;
485+
segment.options.maybeBundledConfigIds = {
486+
'other': ['config21'],
487+
'slack': ['slack99'] // should be ignored
488+
};
489+
segment.normalize(object);
490+
491+
assert(object);
492+
assert(object._metadata);
493+
assert.deepEqual(object._metadata.bundledIds, ['config21']);
494+
});
495+
496+
it('should generate a list of multiple bundled destination config ids when `addBundledMetadata` is set', function() {
497+
segment.options.addBundledMetadata = true;
498+
segment.options.maybeBundledConfigIds = {
499+
'other': ['config21'],
500+
'another': ['anotherConfig99'],
501+
'slack': ['slack99'] // should be ignored
502+
};
503+
segment.normalize(object);
504+
505+
assert(object);
506+
assert(object._metadata);
507+
assert.deepEqual(object._metadata.bundledIds, ['config21', 'anotherConfig99']);
508+
});
481509
});
482510

483511
it('should pick up messageId from AJS', function() {

0 commit comments

Comments
 (0)