Skip to content

BUG: (legacy 1.33.0) track function does not wait for request to complete before callback #2440

@whitestripe42

Description

@whitestripe42

Describe the bug

I'm currently working in legacy code that uses the RudderStack SDK version 1.33.0. For technical reasons, we need to use a workaround involving window.location.replace. Before we replace the URL, we'd like to track an event.

When calling replace in track's callback, it seems that:

  • The callback runs immediately.
  • The network request starts, but it is cancelled.
  • The event isn't logged.

I understand we're using a very outdated version of the SDK. I'm wondering:

  • Was this behaviour changed/fixed in a later version of the SDK?
  • We'd like to avoid breaking changes and a major version upgrade, if at all possible. Could this be fixed for 1.x at all?

To Reproduce

  • Open browser console and ensure logs are preserved for both the Network tab and Console tab.
  • Use the following snippet to simulate the issue:
window.rudderanalytics.track("some_event", () => {
  window.location.replace("https://example.com");
});
  • Observe the network request is cancelled:
Image

Expected behavior

  • The callback executes only after the request has completed.
  • Not a requirement, but it makes sense to me that the callback should be given an argument indicating success of failure (and/or, ideally the response itself). From what I can tell, the callback doesn't receive any args.

The v1.1 documentation for this function states (emphasis mine):

Called after the successful execution of the track call.

Additional Information (please complete the following information):

  • SDK installation type: CDN (unsure)
  • SDK version: 1.33.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingopen sourcePRs or issues originating from the open-source community

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions