Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixes buffering for legacy destinations #1067

Merged
merged 1 commit into from
Apr 12, 2024
Merged

Conversation

oscb
Copy link
Contributor

@oscb oscb commented Apr 12, 2024

Fixes the Classic Destinations buffering to properly buffer events while not loaded

  • Fixed shouldBuffer check as the starting state changed from false to undefined for ready/initialized. Hence events were bypassing buffer all the time.

  • Changed the behaviour of scheduleFlush as previously it was being called after the timeout and ignoring if the plugin had finished initializing. The retry would work properly if the plugin throws an error but Bing/FB don't hence it was marking those events as sent.

    • TODO: This logic could be refactored in the future. Seems particularly convoluted and it should probably listen to onReady and onInitialized instead of retrying at intervals.
  • I've included a changeset (psst. run yarn changeset. Read about changesets here).

Copy link

changeset-bot bot commented Apr 12, 2024

🦋 Changeset detected

Latest commit: 37282e5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@segment/analytics-next Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@@ -192,7 +192,7 @@ export class LegacyDestination implements InternalPluginWithAddMiddleware {
return (
// page events can't be buffered because of destinations that automatically add page views
ctx.event.type !== 'page' &&
(isOffline() || this._ready === false || this._initialized === false)
(isOffline() || this._ready !== true || this._initialized !== true)
Copy link
Contributor

@silesky silesky Apr 12, 2024

Choose a reason for hiding this comment

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

Nit: Couldn't we just get rid of the explicit false and do if (!this.ready) etc?

Just looks a bit weird in JS -- It'd make me think _ready could be an object or a string or whatever. 😄

@oscb oscb merged commit e3f3bee into master Apr 12, 2024
5 checks passed
@oscb oscb deleted the oscb/fixLegacyDestinations branch April 12, 2024 21:23
@github-actions github-actions bot mentioned this pull request Apr 5, 2024
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.

3 participants