https://github.com/choojs/nanobeacon
Small navigator.sendBeacon wrapper
https://github.com/choojs/nanobeacon
Last synced: 12 months ago
JSON representation
Small navigator.sendBeacon wrapper
- Host: GitHub
- URL: https://github.com/choojs/nanobeacon
- Owner: choojs
- License: mit
- Created: 2017-06-07T22:36:36.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2022-12-27T09:16:32.000Z (over 3 years ago)
- Last Synced: 2025-06-08T22:39:43.664Z (about 1 year ago)
- Language: JavaScript
- Size: 10.7 KB
- Stars: 25
- Watchers: 2
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nanobeacon [![stability][0]][1]
[![npm version][2]][3] [![build status][4]][5]
[![downloads][8]][9] [![js-standard-style][10]][11]
Small `navigator.sendBeacon` wrapper. Sends an HTTP request with priority
`lowest` to a remote host, and ensures it arrives without blocking page
navigation. Useful for sending analytics data.
Also a friendly reminder not to ever store people's IP addresses. Only store
the minimum amount of data needed to inform decisions. Be kind, don't give
analytics a bad name.
## Usage
```js
var nanobeacon = require('nanobeacon')
var url = 'http://jsfiddle.net?sendbeacon'
var ok = nanobeacon(url, { hello: 'world' })
var msg = ok ? 'OK' : 'NOT OK'
document.body.innerHTML = '
message status: ' + msg + '
'
```
## API
### `ok = nanobeacon(url, [data])`
Send a request with a payload to a remote host.
If user has enabled Do Not Track (`window.navigator.doNotTrack`) then no beacon will be sent and nanobeacon will return `false`.
## See Also
- [dom/navigator/sendBeacon](http://devdocs.io/dom/navigator/sendbeacon)
## License
[MIT](https://tldrlegal.com/license/mit-license)
[0]: https://img.shields.io/badge/stability-experimental-orange.svg?style=flat-square
[1]: https://nodejs.org/api/documentation.html#documentation_stability_index
[2]: https://img.shields.io/npm/v/nanobeacon.svg?style=flat-square
[3]: https://npmjs.org/package/nanobeacon
[4]: https://img.shields.io/travis/yoshuawuyts/nanobeacon/master.svg?style=flat-square
[5]: https://travis-ci.org/yoshuawuyts/nanobeacon
[6]: https://img.shields.io/codecov/c/github/yoshuawuyts/nanobeacon/master.svg?style=flat-square
[7]: https://codecov.io/github/yoshuawuyts/nanobeacon
[8]: http://img.shields.io/npm/dm/nanobeacon.svg?style=flat-square
[9]: https://npmjs.org/package/nanobeacon
[10]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square
[11]: https://github.com/feross/standard