Skip to content

Hapi plugin to track requests and pre-responses in Segment.IO

License

Notifications You must be signed in to change notification settings

theworkflow/hapi-segment-analytics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

MIT

About

Hapi plugin to track requests and pre-responses in Segment.IO

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published