From 3334c3af0d20763188b665ca624eaac3bdb5271d Mon Sep 17 00:00:00 2001 From: Gabriel P Samson Date: Wed, 3 Feb 2021 13:36:08 -0800 Subject: [PATCH 1/7] Spike intersection of bundled and maybeBundledConfigIds --- integrations/segmentio/lib/index.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/integrations/segmentio/lib/index.js b/integrations/segmentio/lib/index.js index f549d5a6c..a04f33a55 100644 --- a/integrations/segmentio/lib/index.js +++ b/integrations/segmentio/lib/index.js @@ -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('unbundledIntegrationIds', []) + .option('maybeBundledConfigIds', []); /** * Get the store. @@ -315,10 +317,27 @@ Segment.prototype.normalize = function(message) { } if (this.options.addBundledMetadata) { var bundled = keys(this.analytics.Integrations); + + // 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[name]) { + continue + } + + for (var i = 0; i < maybeBundledConfigIds[name].length; i++) { + var id = maybeBundledConfigIds[name][i] + 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.bundledConfigIds = bundledConfigIds; msg._metadata.unbundledConfigIds = this.options.unbundledConfigIds; } this.debug('normalized %o', msg); From 9e6652ba1b510f48478e0a13fc829011c1540ec6 Mon Sep 17 00:00:00 2001 From: Gabriel P Samson Date: Wed, 3 Feb 2021 23:13:22 -0800 Subject: [PATCH 2/7] Update test cases and short-circuit when maybeBundledConfigIds falsy --- integrations/segmentio/lib/index.js | 3 +++ integrations/segmentio/test/index.test.js | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/integrations/segmentio/lib/index.js b/integrations/segmentio/lib/index.js index a04f33a55..eeff4d809 100644 --- a/integrations/segmentio/lib/index.js +++ b/integrations/segmentio/lib/index.js @@ -323,6 +323,9 @@ Segment.prototype.normalize = function(message) { var bundledConfigIds = [] for (var i = 0; i < bundled.length; i++) { var name = bundled[i] + if (!maybeBundledConfigIds) { + break + } if (!maybeBundledConfigIds[name]) { continue } diff --git a/integrations/segmentio/test/index.test.js b/integrations/segmentio/test/index.test.js index 43485a7a9..aa973529c 100644 --- a/integrations/segmentio/test/index.test.js +++ b/integrations/segmentio/test/index.test.js @@ -478,6 +478,29 @@ describe('Segment.io', function() { assert(object); assert(!object._metadata); }); + + it('should add a list of unbundled destination config ids when `addBundledMetadata` is set', function() { + segment.options.addBundledMetadata = true; + segment.options.unbundledConfigIds = ['config1']; + segment.normalize(object); + + assert(object); + assert(object._metadata); + assert.deepEqual(object._metadata.unbundledConfigIds, ['config1']); + }); + + 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.bundledConfigIds, ['config21']); + }); }); it('should pick up messageId from AJS', function() { From 9d2e22ac1de9fb9faffbbd6920510eb43a1e9a97 Mon Sep 17 00:00:00 2001 From: Gabriel P Samson Date: Thu, 4 Feb 2021 21:16:09 -0800 Subject: [PATCH 3/7] Fix bad loop + Add test --- integrations/segmentio/lib/index.js | 13 +++++++------ integrations/segmentio/test/index.test.js | 19 +++++++++++++++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/integrations/segmentio/lib/index.js b/integrations/segmentio/lib/index.js index eeff4d809..51c80e1ad 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 @@ -65,8 +65,8 @@ var Segment = (exports = module.exports = integration('Segment.io') .option('retryQueue', true) .option('addBundledMetadata', false) .option('unbundledIntegrations', [])) - .option('unbundledIntegrationIds', []) - .option('maybeBundledConfigIds', []); + .option('unbundledConfigIds', []) + .option('maybeBundledConfigIds', {}); /** * Get the store. @@ -317,6 +317,7 @@ 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. @@ -330,8 +331,8 @@ Segment.prototype.normalize = function(message) { continue } - for (var i = 0; i < maybeBundledConfigIds[name].length; i++) { - var id = maybeBundledConfigIds[name][i] + for (var j = 0; j < maybeBundledConfigIds[name].length; j++) { + var id = maybeBundledConfigIds[name][j] bundledConfigIds.push(id) } } @@ -339,8 +340,8 @@ Segment.prototype.normalize = function(message) { msg._metadata = msg._metadata || {}; msg._metadata.bundled = bundled; - msg._metadata.unbundled = this.options.unbundledIntegrations; msg._metadata.bundledConfigIds = bundledConfigIds; + msg._metadata.unbundled = this.options.unbundledIntegrations; msg._metadata.unbundledConfigIds = this.options.unbundledConfigIds; } this.debug('normalized %o', msg); diff --git a/integrations/segmentio/test/index.test.js b/integrations/segmentio/test/index.test.js index aa973529c..5451bff08 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() { @@ -501,6 +502,20 @@ describe('Segment.io', function() { assert(object._metadata); assert.deepEqual(object._metadata.bundledConfigIds, ['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.bundledConfigIds, ['config21', 'anotherConfig99']); + }); }); it('should pick up messageId from AJS', function() { From 7bbbcb4118236e0f48ffddc1b99b898b3df8dc33 Mon Sep 17 00:00:00 2001 From: Gabriel P Samson Date: Fri, 5 Feb 2021 00:08:55 -0800 Subject: [PATCH 4/7] Update segmentio version to 4.4.1 --- integrations/segmentio/HISTORY.md | 9 +++++++++ integrations/segmentio/package.json | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/integrations/segmentio/HISTORY.md b/integrations/segmentio/HISTORY.md index 561ca3b7a..0c494f57a 100644 --- a/integrations/segmentio/HISTORY.md +++ b/integrations/segmentio/HISTORY.md @@ -1,3 +1,12 @@ +4.4.1 / 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/package.json b/integrations/segmentio/package.json index 20cc40010..5bff3dd1a 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.1", "keywords": [ "analytics.js", "analytics.js-integration", From f9960ccf85081694ddc6feeee83b1e3d214d385f Mon Sep 17 00:00:00 2001 From: Gabriel Samson Date: Mon, 8 Feb 2021 12:40:26 -0800 Subject: [PATCH 5/7] Update metadata ordering Co-authored-by: Marcus Ericsson <36717+mericsson@users.noreply.github.com> --- integrations/segmentio/lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/segmentio/lib/index.js b/integrations/segmentio/lib/index.js index 51c80e1ad..c461fb01b 100644 --- a/integrations/segmentio/lib/index.js +++ b/integrations/segmentio/lib/index.js @@ -340,8 +340,8 @@ Segment.prototype.normalize = function(message) { msg._metadata = msg._metadata || {}; msg._metadata.bundled = bundled; - msg._metadata.bundledConfigIds = bundledConfigIds; msg._metadata.unbundled = this.options.unbundledIntegrations; + msg._metadata.bundledConfigIds = bundledConfigIds; msg._metadata.unbundledConfigIds = this.options.unbundledConfigIds; } this.debug('normalized %o', msg); From 7d544aa75b219b83dd91c235821e3dcf6d9462ae Mon Sep 17 00:00:00 2001 From: Gabriel P Samson Date: Tue, 9 Feb 2021 13:12:34 -0800 Subject: [PATCH 6/7] Fix version number --- integrations/segmentio/HISTORY.md | 2 +- integrations/segmentio/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/integrations/segmentio/HISTORY.md b/integrations/segmentio/HISTORY.md index 0c494f57a..3f7306f7e 100644 --- a/integrations/segmentio/HISTORY.md +++ b/integrations/segmentio/HISTORY.md @@ -1,4 +1,4 @@ -4.4.1 / 2020-02-05 +4.4.0 / 2020-02-05 ================== * Removes the `bundledConfigIds` _setting_ and instead generates `bundledConfigIds` using the intersection diff --git a/integrations/segmentio/package.json b/integrations/segmentio/package.json index 5bff3dd1a..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.4.1", + "version": "4.4.0", "keywords": [ "analytics.js", "analytics.js-integration", From 8569f315479f839002ee96743380f65a67f2f304 Mon Sep 17 00:00:00 2001 From: Gabriel P Samson Date: Thu, 18 Feb 2021 11:22:41 -0800 Subject: [PATCH 7/7] Rename bundledConfigIds + Remove unbundledConfigIds --- integrations/segmentio/lib/index.js | 3 +-- integrations/segmentio/test/index.test.js | 14 ++------------ 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/integrations/segmentio/lib/index.js b/integrations/segmentio/lib/index.js index c461fb01b..4a409e325 100644 --- a/integrations/segmentio/lib/index.js +++ b/integrations/segmentio/lib/index.js @@ -341,8 +341,7 @@ Segment.prototype.normalize = function(message) { msg._metadata = msg._metadata || {}; msg._metadata.bundled = bundled; msg._metadata.unbundled = this.options.unbundledIntegrations; - msg._metadata.bundledConfigIds = bundledConfigIds; - msg._metadata.unbundledConfigIds = this.options.unbundledConfigIds; + msg._metadata.bundledIds = bundledConfigIds; } this.debug('normalized %o', msg); this.ampId(ctx); diff --git a/integrations/segmentio/test/index.test.js b/integrations/segmentio/test/index.test.js index 5451bff08..e2836b2f3 100644 --- a/integrations/segmentio/test/index.test.js +++ b/integrations/segmentio/test/index.test.js @@ -480,16 +480,6 @@ describe('Segment.io', function() { assert(!object._metadata); }); - it('should add a list of unbundled destination config ids when `addBundledMetadata` is set', function() { - segment.options.addBundledMetadata = true; - segment.options.unbundledConfigIds = ['config1']; - segment.normalize(object); - - assert(object); - assert(object._metadata); - assert.deepEqual(object._metadata.unbundledConfigIds, ['config1']); - }); - it('should generate and add a list of bundled destination config ids when `addBundledMetadata` is set', function() { segment.options.addBundledMetadata = true; segment.options.maybeBundledConfigIds = { @@ -500,7 +490,7 @@ describe('Segment.io', function() { assert(object); assert(object._metadata); - assert.deepEqual(object._metadata.bundledConfigIds, ['config21']); + assert.deepEqual(object._metadata.bundledIds, ['config21']); }); it('should generate a list of multiple bundled destination config ids when `addBundledMetadata` is set', function() { @@ -514,7 +504,7 @@ describe('Segment.io', function() { assert(object); assert(object._metadata); - assert.deepEqual(object._metadata.bundledConfigIds, ['config21', 'anotherConfig99']); + assert.deepEqual(object._metadata.bundledIds, ['config21', 'anotherConfig99']); }); });