diff --git a/integrations/segmentio/HISTORY.md b/integrations/segmentio/HISTORY.md index 561ca3b7a..3f7306f7e 100644 --- a/integrations/segmentio/HISTORY.md +++ b/integrations/segmentio/HISTORY.md @@ -1,3 +1,12 @@ +4.4.0 / 2020-02-05 +================== + + * Removes the `bundledConfigIds` _setting_ and instead generates `bundledConfigIds` using the intersection + of `bundled` destinations and the new `maybeBundledConfigIds` setting. `bundledConfigIds` and `unbundledConfigIds` + is still appended to event metadata. This change is meant to ensure that `bundledConfigIds` only includes the + subset of destinations that is generated at runtime for the `bundled` array. + * Fixes the use of `const` from a previous release. + 4.3.0 / 2020-01-13 ================== diff --git a/integrations/segmentio/lib/index.js b/integrations/segmentio/lib/index.js index f549d5a6c..4a409e325 100644 --- a/integrations/segmentio/lib/index.js +++ b/integrations/segmentio/lib/index.js @@ -18,7 +18,7 @@ var utm = require('@segment/utm-params'); var uuid = require('@lukeed/uuid').v4; var Queue = require('@segment/localstorage-retry'); -const json = JSON; +var json = JSON; /** * Cookie options @@ -64,7 +64,9 @@ var Segment = (exports = module.exports = integration('Segment.io') .option('saveCrossDomainIdInLocalStorage', true) .option('retryQueue', true) .option('addBundledMetadata', false) - .option('unbundledIntegrations', [])); + .option('unbundledIntegrations', [])) + .option('unbundledConfigIds', []) + .option('maybeBundledConfigIds', {}); /** * Get the store. @@ -315,11 +317,31 @@ Segment.prototype.normalize = function(message) { } if (this.options.addBundledMetadata) { var bundled = keys(this.analytics.Integrations); + var maybeBundledConfigIds = this.options.maybeBundledConfigIds + + // Generate a list of bundled config IDs using the intersection of + // bundled destination names and maybe bundled config IDs. + var bundledConfigIds = [] + for (var i = 0; i < bundled.length; i++) { + var name = bundled[i] + if (!maybeBundledConfigIds) { + break + } + if (!maybeBundledConfigIds[name]) { + continue + } + + for (var j = 0; j < maybeBundledConfigIds[name].length; j++) { + var id = maybeBundledConfigIds[name][j] + bundledConfigIds.push(id) + } + } + + msg._metadata = msg._metadata || {}; msg._metadata.bundled = bundled; msg._metadata.unbundled = this.options.unbundledIntegrations; - msg._metadata.bundledConfigIds = this.options.bundledConfigIds; - msg._metadata.unbundledConfigIds = this.options.unbundledConfigIds; + msg._metadata.bundledIds = bundledConfigIds; } this.debug('normalized %o', msg); this.ampId(ctx); diff --git a/integrations/segmentio/package.json b/integrations/segmentio/package.json index 20cc40010..5adabbe6c 100644 --- a/integrations/segmentio/package.json +++ b/integrations/segmentio/package.json @@ -1,7 +1,7 @@ { "name": "@segment/analytics.js-integration-segmentio", "description": "The Segmentio analytics.js integration.", - "version": "4.3.1", + "version": "4.4.0", "keywords": [ "analytics.js", "analytics.js-integration", diff --git a/integrations/segmentio/test/index.test.js b/integrations/segmentio/test/index.test.js index 43485a7a9..e2836b2f3 100644 --- a/integrations/segmentio/test/index.test.js +++ b/integrations/segmentio/test/index.test.js @@ -449,8 +449,9 @@ describe('Segment.io', function() { segment = new Segment(options); ajs.use(Segment); ajs.use(integration('other')); + ajs.use(integration('another')); ajs.add(segment); - ajs.initialize({ other: {} }); + ajs.initialize({ other: {}, another: {} }); }); it('should add a list of bundled integrations when `addBundledMetadata` is set', function() { @@ -459,7 +460,7 @@ describe('Segment.io', function() { assert(object); assert(object._metadata); - assert.deepEqual(object._metadata.bundled, ['Segment.io', 'other']); + assert.deepEqual(object._metadata.bundled, ['Segment.io', 'other', 'another']); }); it('should add a list of unbundled integrations when `addBundledMetadata` and `unbundledIntegrations` are set', function() { @@ -478,6 +479,33 @@ describe('Segment.io', function() { assert(object); assert(!object._metadata); }); + + it('should generate and add a list of bundled destination config ids when `addBundledMetadata` is set', function() { + segment.options.addBundledMetadata = true; + segment.options.maybeBundledConfigIds = { + 'other': ['config21'], + 'slack': ['slack99'] // should be ignored + }; + segment.normalize(object); + + assert(object); + assert(object._metadata); + assert.deepEqual(object._metadata.bundledIds, ['config21']); + }); + + it('should generate a list of multiple bundled destination config ids when `addBundledMetadata` is set', function() { + segment.options.addBundledMetadata = true; + segment.options.maybeBundledConfigIds = { + 'other': ['config21'], + 'another': ['anotherConfig99'], + 'slack': ['slack99'] // should be ignored + }; + segment.normalize(object); + + assert(object); + assert(object._metadata); + assert.deepEqual(object._metadata.bundledIds, ['config21', 'anotherConfig99']); + }); }); it('should pick up messageId from AJS', function() {