0.1.0 • Published 8 years ago
hapi-segment-analytics v0.1.0
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.
License
0.1.0
8 years ago