Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sushantrahate/send-beacon-nodejs
It's intended to be used for sending analytics data to a web server when the user navigates away from the page.
https://github.com/sushantrahate/send-beacon-nodejs
javascript nodejs sendbeacon
Last synced: 11 days ago
JSON representation
It's intended to be used for sending analytics data to a web server when the user navigates away from the page.
- Host: GitHub
- URL: https://github.com/sushantrahate/send-beacon-nodejs
- Owner: sushantrahate
- Created: 2024-07-15T14:38:56.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-07-21T10:54:35.000Z (4 months ago)
- Last Synced: 2024-07-21T11:58:18.010Z (4 months ago)
- Topics: javascript, nodejs, sendbeacon
- Language: HTML
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Navigator: sendBeacon() method Example
[MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon)
The `navigator.sendBeacon()` method asynchronously sends an HTTP POST request containing a small amount of data to a web server.
It's intended to be used for sending analytics data to a web server when the user navigates away from the page.
> Avoid using **unload** and **beforeunload** events to send analytics at the end of a session.
## Usage
Download the repository, install dependencies with `npm install`, and run the server with `node server.js`.
```sh
git clone https://github.com/sushantrahate/send-beacon-nodejs.git
cd send-beacon-nodejs
npm install
node server.js
```## Access the App
Open a browser and navigate to http://localhost:3000/index.html. When you leave the page, the sendBeacon API gets called.