Skip to content
This repository has been archived by the owner on Sep 22, 2023. It is now read-only.

Commit

Permalink
update browser debugging (#959)
Browse files Browse the repository at this point in the history
* update browser debugging

* Edits

* Update includes/sdk-troubleshooting-and-debugging/browser.md

Co-authored-by: Alyssa Yu <[email protected]>

---------

Co-authored-by: Mark Zegarelli <[email protected]>
Co-authored-by: Alyssa Yu <[email protected]>
  • Loading branch information
3 people authored Sep 21, 2023
1 parent 92754b1 commit 1246fae
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions includes/sdk-troubleshooting-and-debugging/browser.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,14 @@ Cross-origin resource sharing (CORS) prevents a malicious site from reading anot

If you have set up an API proxy and run into configuration issues related to that on a platform you’ve selected, that’s no longer an SDK issue but an integration issue between your application and the service provider.

##### Event Dropping When Closes the Browser or Leaves the Page
##### Events fired but no network requests

If you [set the logger to "Debug" level](./#debug-mode), and see track calls in the developer console, the `track()` method has been called. If you don't see the corresponding event in Amplitude, the Amplitude Instrumentation Explorer Chrome extension, or the network request tab of the browser, the event wasn't sent to Amplitude. Events are fired and placed in the SDK's internal queue upon a successful `track()` call, but sometimes these queued events may not send successfully. This can happen when an in-progress HTTP request is cancelled. For example, if you close the browser or leave the page.

There are two ways to address this issue:

1. If you use standard network requests, set the transport to `beacon` during initialization or set the transport to `beacon` upon page exit. `sendBeacon` doesn't work in this case because it sends events in the background, and doesn't return server responses like `4xx` or `5xx`. As a result, it doesn't retry on failure. `sendBeacon` sends only scheduled requests in the background. For more information, see the [sendBeacon](./#use-sendbeacon) section.

2. To make track() synchronous, [add the `await` keyword](./#callback) before the call.

If you're using standard network requests, scheduled requests might be dropped if the user closes the browser or leaves the page. To solve this issue, you might want to set the transport to `beacon` during initialization or set the transport to `beacon` upon page exit. However, because `sendBeacon` will send events in the background, it doesn't return server responses and thus cannot retry on failure responses like 4xx or 5xx errors. Also, note that only scheduled requests will be sent out in the background with a `sendBeacon` configuration.

Please refer to the [sendBeacon](./#use-sendbeacon) section for more instructions.

0 comments on commit 1246fae

Please sign in to comment.