Skip to content

Beacon API support #1167

@erykpiast

Description

@erykpiast

Did you consider adding support for the Beacon API as a "transport layer" alternative to fetch/XHR? This native API is created with analytics in mind and helps increasing reliability of client-side data collection.

To quote MDN.

The Beacon API is used to send an asynchronous and non-blocking request to a web server. The request does not expect a response. Unlike requests made using XMLHttpRequest or the Fetch API, the browser guarantees to initiate beacon requests before the page is unloaded and to run them to completion.

Nowadays the browser support for Beacon API is excellent (96%+), from my perspective is a no-brainer.

To give you an example of what it could help with practically - checkout flows provided externally, e.g. by Stripe. Imagine you have a payment plan selection in your webapp, but the payment itself happens on a different domain. Measuring the conversion - a ratio of clicks on the "Checkout" button in your app and successful payment - it's quite difficult with regular async HTTP requests as they're interrupted when the page unloads. If you redirect to an external domain right in the button click handler and you don't wait for the analytics request to finish, the risk of missing an event is quite high. Delaying the redirection it is not ideal, as it degrades user experience. Beacon API would solve this issue ultimately.

I wonder if there are any concerns about having this as an option? I found this comment from @f2prateek mentioning Beacon API and some reasons to not introduce it. Apart from that, no serious take on it there and no mention whatsoever in this repository, which is quite surprising.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions