hapi-segment-analytics
v0.1.0
Published
Hapi plugin to track request and pre-response data to Segment.IO
Downloads
4
Maintainers
Readme
hapi-segment-analytics
Hapi plugin to track request and pre-response data to Segment.IO
Table of Contents
Install
$ npm install hapi-segment-analytics
Segment.IO Configuration
To get started with Segment, check out their documentation
Usage
server.register({
register: require('hapi-segment-analytics'),
options: {
segmentKey: 'secret',
segmentOptions: {} // set flush props
getToken: (request) => request.id, // custom logic
skip: (request) => false // should track?
}
})
getToken
is a custom function used to grab some type of identifier to the end user.
For example, this may be an auth token.
// Get auth token from request headers
// Example headers
// request.headers = { authorization: 'Token 123' }
const getToken = (request) => request.headers['authorization'].split(' ')[1]
skip
is a custom function that skips tracking a onRequest
and onPreResponse
if
conditions are met.
// Skip tracking requests if the admin token is present
const skip = (request) => request.headers['authorization'].split(' ')[1] === 'adminToken'
Contributing
Contributions welcome! Please read the contributing guidelines first.