From a9ac0815b17d01e42b08a10944a05ad5d7c4b3f3 Mon Sep 17 00:00:00 2001 From: Peter Mekhaeil <4616064+petermekhaeil@users.noreply.github.com> Date: Sun, 28 Jan 2024 21:30:23 +0800 Subject: [PATCH] Create js-beacon-api.md --- learnings/js-beacon-api.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 learnings/js-beacon-api.md diff --git a/learnings/js-beacon-api.md b/learnings/js-beacon-api.md new file mode 100644 index 0000000..af397ca --- /dev/null +++ b/learnings/js-beacon-api.md @@ -0,0 +1,12 @@ +# Send analytics data using the Beacon API + +The `navigator.sendBeacon()` method is intended to be used for sending analytics data to a server. + +```js +navigator.sendBeacon("/log", analyticsData); +``` + +- It sends the HTTP POST request asynchronously, with no access to the server response. +- The request is non-blocking, causing no delay to unload or the next navigation. + +See [documentation](https://developer.mozilla.org/en-US/docs/Web/API/Beacon_API) on usage.