Skip to content

It's intended to be used for sending analytics data to a web server when the user navigates away from the page.

Notifications You must be signed in to change notification settings

sushantrahate/send-beacon-nodejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Navigator: sendBeacon() method Example

MDN Web Docs

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.

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.

About

It's intended to be used for sending analytics data to a web server when the user navigates away from the page.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published