Skip to content

Conversation

@gpsamson
Copy link
Contributor

@gpsamson gpsamson commented Feb 3, 2021

What does this PR do?
This pull request builds a list of bundledds based on the intersection between bundled and maybeBundledConfigIds. bundledIds is then appended to each event's metadata object.

The related ajs-renderer change can be found here: https://github.com/segmentio/ajs-renderer/pull/256.

Example metadata object
image

  • 601c3fef8942cb2ad5d70cdf is the FullStory instance that is not Connection Mode configurable because there is only a browser integration.
  • 601c3c238942cb7cb5d70cde is the Google Analytics instance configured in Device Mode.
  • 601c4f8164b0701d3b6b78cd is the HubSpot instance that is not Connection Mode configurable, but defaults to Device Mode because it's an a.js source.
  • 601c40c46b6df7898d069abf is the Amplitude instance that is configured explicitly in Cloud Mode.

Are there breaking changes in this PR?
No. We specifically are adding new metadata fields to avoid introducing breaking changes to bundled and unbundled.

Testing

  • Testing completed successfully in stage via end-to-end tests with the related ajs-renderer change.
  • Existing and new unit tests are passing

Any background context you want to provide?

Is there parity with the server-side/android/iOS integration components (if applicable)?

Does this require a new integration setting? If so, please explain how the new setting works

Links to helpful docs and other external resources

@gpsamson gpsamson changed the title Spike intersection of bundled and maybeBundledConfigIds [STRATCONN-588] Generate bundledConfigIds Feb 4, 2021
@gpsamson gpsamson marked this pull request as ready for review February 5, 2021 07:59
msg._metadata.bundledConfigIds = bundledConfigIds;
msg._metadata.unbundled = this.options.unbundledIntegrations;
msg._metadata.bundledConfigIds = this.options.bundledConfigIds;
msg._metadata.unbundledConfigIds = this.options.unbundledConfigIds;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided not to ignore empty bundledConfigIds and unbundledConfigIds arrays so it is clear when an event was tracked using this new version of segmentio.

var Queue = require('@segment/localstorage-retry');

const json = JSON;
var json = JSON;
Copy link
Contributor Author

@gpsamson gpsamson Feb 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was unintentionally switched to const in #553.

if (!maybeBundledConfigIds) {
break
}
if (!maybeBundledConfigIds[name]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the casing is the same of destination names in maybeBundledConfigIds and analytics.Integrations e.g. Google Analytics === Google Analytics vs google-analytics.. but perhaps something to double check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, the casing here is the same but they depend on two different sources.

- `bundled` depends on the name that is defined within the integration code itself: https://github.com/segmentio/analytics.js-integrations/blob/master/integrations/google-analytics/lib/index.js#L37
- `bundledConfigIDs` depends on the defintiion creation name: https://github.com/segmentio/ajs-renderer/pull/256/files#diff-ca733fb7a822baffec24f4f426ccb07fce89f5b4d5856f848be4845d1d40e12bR44

The chance of these being different is unlikely but possible. Fwiw, the integration wouldn't receive the proper settings if the name within the integration code doesn't match the destination creation name because settings are keyed by the definition creation name.

Copy link
Contributor

@briemcnally briemcnally Feb 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to Gabe's comment, I spot checked a few destinations which I know have undergone name changes and the name defined in integration code marched the definition creation name.


// Generate a list of bundled config IDs using the intersection of
// bundled destination names and maybe bundled config IDs.
var bundledConfigIds = []
Copy link
Contributor

@mericsson mericsson Feb 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think var bundledConfigIds = [] should be defined outside of his conditional for clarity. This works currently because of use of var vs let/const.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so -- msg._metadata.bundledConfigIds (L343) is defined within the conditional. I'm also mimicking the scope of bundled.

Co-authored-by: Marcus Ericsson <36717+mericsson@users.noreply.github.com>
Comment on lines +68 to +69
.option('unbundledConfigIds', [])
.option('maybeBundledConfigIds', {});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we were to conditionally add these arrays in ajs-renderer we would still default to empty values here. 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I agree.

}

for (var j = 0; j < maybeBundledConfigIds[name].length; j++) {
var id = maybeBundledConfigIds[name][j]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we maybe want to see if maybeBundledConfigIds[name] has more than one configId? In example case where maybeBundledConfigIds looks like the below, wouldn't we want to collect stats since that would mean they have multiple device mode configs of a destination in device mode, which is not allowed?

maybeBundledConfigIds: {
       Fullstory: [ config1, config2]
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

msg._metadata.unbundled = this.options.unbundledIntegrations;
msg._metadata.bundledConfigIds = this.options.bundledConfigIds;
msg._metadata.bundledConfigIds = bundledConfigIds;
msg._metadata.unbundledConfigIds = this.options.unbundledConfigIds;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unbundledConfigIds is not used in data plane so it could be removed later on.

"name": "@segment/analytics.js-integration-segmentio",
"description": "The Segmentio analytics.js integration.",
"version": "4.3.1",
"version": "4.4.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should this be 4.4.0 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, thanks for catching,

var bundledConfigIds = []
for (var i = 0; i < bundled.length; i++) {
var name = bundled[i]
if (!maybeBundledConfigIds) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be clearer if this conditional was outside of the loop since it does not depend on anything in bundled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd have to refactor and wrap the for-loop in a conditional. I can go either way but was trying to avoid nested conditionals.

if (maybeBundledConfigIds) {
  for (var i = 0; i < bundled.length; i++) { ... }
}

Copy link
Contributor

@mericsson mericsson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm - just one code cleanliness issue #555 (comment)

@gpsamson gpsamson merged commit a441a1f into master Feb 22, 2021
@gpsamson gpsamson deleted the maybe-bundled branch February 22, 2021 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants