# hapi-segment-analytics

> Hapi plugin to track request and pre-response data to Segment.IO

Latest version **0.1.0** (published 2017-05-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install hapi-segment-analytics
pnpm add hapi-segment-analytics
yarn add hapi-segment-analytics
bun add hapi-segment-analytics
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2017-05-29 |
| First published | 2017-05-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | 6.10.x |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jeremiah Harlan |
| Maintainers | harlanj |
| Keywords | hapi, segment, analytics, tracking, request |

## Links

- npm: https://www.npmjs.com/package/hapi-segment-analytics
- npm.io page: https://npm.io/package/hapi-segment-analytics

## Dependencies (1)

- [analytics-node](https://npm.io/package/analytics-node.md) 2.4.1

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 0.1.0 (latest) — 2017-05-29

## README

# hapi-segment-analytics

> Hapi plugin to track request and pre-response data to Segment.IO

## Table of Contents

- [Install](#install)
- [Usage](#usage)
- [Contributing](#contributing)
- [License](#license)

## Install

`$ npm install hapi-segment-analytics`

## Segment.IO Configuration

To get started with Segment, check out their [documentation](https://segment.com/docs/sources/server/node/#configuration)

## 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.

```js
// 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.

```js
// 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](CONTRIBUTING.md) first.

## License

[MIT](LICENSE.md)

[segmentDocs]: https://segment.com/docs/sources/server/node/#configuration

---
_Source: https://npm.io/package/hapi-segment-analytics · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
