# analytics-forwarder

> Forwards analytics events to S3 via API Gateway and Firehose

Latest version **0.1.2** (published 2023-09-06) · ISC license · 0 weekly downloads

## Install

```sh
npm install analytics-forwarder
pnpm add analytics-forwarder
yarn add analytics-forwarder
bun add analytics-forwarder
```

## 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.2 |
| Published | 2023-09-06 |
| First published | 2023-07-11 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 40.6 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | mmessier_dispatch |

## Links

- npm: https://www.npmjs.com/package/analytics-forwarder
- Repository: https://github.com/DispatchMe/analytics-forwarder
- Homepage: https://github.com/DispatchMe/analytics-forwarder#readme
- Issues: https://github.com/DispatchMe/analytics-forwarder/issues
- npm.io page: https://npm.io/package/analytics-forwarder

## Dependencies (5)

- [uuid](https://npm.io/package/uuid.md) 3.1.0
- [expect](https://npm.io/package/expect.md) 1.20.2
- [js-md5](https://npm.io/package/js-md5.md) 0.6.1
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [detect-browser](https://npm.io/package/detect-browser.md) 2.4.0

## Recent versions

- 0.1.2 (latest) — 2023-09-06
- 0.1.1 — 2023-07-11

## README

Analytics Forwarder
===================
Forwards analytics events to S3 via API Gateway and Firehose. This repo includes the serverless lambda function for the endpoint, as well as the front-end Javascript SDK.

```

                                   .:+oooo+:.
                                ./oooooooooooo/
                            `-+oooooooooooooooo
                         .:+ooooooooooooooooooo
                     `-/ooooooooooooooooooooooo         .-`
                  .:+oooooooooooooooooooooooooo         -oo+:.
              `-/ooooooooooooooooooooo+//+ooooo         -oooooo/-`
            `/ooooooooooooooooooooo/-`    `-+oo         -ooooooooo/`
           `+ooooooooooooooooooo:.            .         -ooooooooooo`
           -oooooooooooooooo+:`                         -ooooooooooo-
           -ooooooooooooo/-                             -ooooooooooo-
           -ooooooooooo/                                -ooooooooooo-
           -ooooooooooo-             .:++/.             -ooooooooooo-
           -ooooooooooo-         `-/oooooooo/-`         -ooooooooooo-
           -ooooooooooo-         +oooooooooooo+         -ooooooooooo-
           -ooooooooooo-         +oooooooooooo+         -ooooooooooo-
           -ooooooooooo-         +oooooooooooo+         -ooooooooooo-
           -ooooooooooo-         +oooooooooooo+         -ooooooooooo-
           -ooooooooooo-         `-/oooooooo/-`         -ooooooooooo-
           -ooooooooooo-             .:++:.             -ooooooooooo-
           -ooooooooooo:                                /ooooooooooo-
           -oooooooooooo+:.                          .:ooooooooooooo-
           -oooooooooooooooo/-`                  `-/oooooooooooooooo-
           `+oooooooooooooooooo+:.            .:+ooooooooooooooooooo`
            `/oooooooooooooooooooo+/-`    `-/ooooooooooooooooooooo+`
              `-/+oooooooooooooooooooo+//+ooooooooooooooooooooo+:`
                  .:+ooooooooooooooooooooooooooooooooooooooo/-
                     `-/oooooooooooooooooooooooooooooooo+:.
                         .:+ooooooooooooooooooooooooo/-`
                            `-/oooooooooooooooooo+:.
                                .:+ooooooooooo/-`
                                   `-/oooo+:.

```

## Lambda Installation (Experimental)

To deploy, after installing nvm:
```
nvm use
npm install -g serverless@1.28.0
npm install
./deploy [ENV]
```


## SDK Usage
### Client ID
```
const tracker = new AnalyticsForwarder({
  keyUrl: <URL_TO_GET_KEY>,
  analyticsUrl: <URL_TO_SEND_ANALYTICS>,
  clientId: <CLIENT_ID>,
  application: 'example',
});

tracker.setUser('1');
tracker.trackEvent('clicked_button', { button_text: 'help' });
```

### Bearer Token
```
const tracker = new AnalyticsForwarder({
  keyUrl: <URL_TO_GET_KEY>,
  analyticsUrl: <URL_TO_SEND_ANALYTICS>,
  bearerToken: <BEARER_TOKEN>,
  application: 'example',
});

tracker.setUser('1', <BEARER_TOKEN>);
tracker.trackEvent('clicked_button', { button_text: 'help' });
```

## Functions

<dl>
<dt><a href="#getFingerprint">getFingerprint()</a> ⇒ <code>Promise</code></dt>
<dd><p>Get a fingerprint for the user based on their IP address and user agent.
Store the fingerprint as a cookie for when the user returns.</p>
</dd>
<dt><a href="#getKey">getKey()</a> ⇒ <code>Promise</code></dt>
<dd><p>Get a the tracking key for the user based on the authentication mode.
If public is true, use a public client ID to get the key.
If public is false, use a bearer token to get the key.</p>
</dd>
<dt><a href="#setUser">setUser(id, bearerToken)</a> ⇒ <code>Promise</code></dt>
<dd><p>Set the current user to track and identify the user in the analytics.</p>
</dd>
<dt><a href="#trackEvent">trackEvent(event, properties)</a> ⇒ <code>Promise</code></dt>
<dd><p>Track an event with certain metadata and properties about the user.</p>
</dd>
<dt><a href="#trackException">trackException(exception, fatal)</a> ⇒ <code>Promise</code></dt>
<dd><p>Track an exception event with the exception and
whether or not it was fatal as properties.</p>
</dd>
<dt><a href="#trackPage">trackPage(page)</a> ⇒ <code>Promise</code></dt>
<dd><p>Track a page event with the name of the page as a property.</p>
</dd>
</dl>

<a name="getFingerprint"></a>

## getFingerprint() ⇒ <code>Promise</code>
Get a fingerprint for the user based on their IP address and user agent.
Store the fingerprint as a cookie for when the user returns.

**Kind**: global function
**Returns**: <code>Promise</code> - A promise with the fingerprint.
<a name="getKey"></a>

## getKey() ⇒ <code>Promise</code>
Get a the tracking key for the user based on the authentication mode.
If public is true, use a public client ID to get the key.
If public is false, use a bearer token to get the key.

**Kind**: global function
**Returns**: <code>Promise</code> - A promise with the tracking key.
<a name="setUser"></a>

## setUser(id, bearerToken) ⇒ <code>Promise</code>
Set the current user to track and identify the user in the analytics.

**Kind**: global function

| Param | Type | Description |
| --- | --- | --- |
| id | <code>String</code> | The id of the user to track. |
| bearerToken | <code>String</code> | The bearer token for the user for non public tracking. |

<a name="trackEvent"></a>

## trackEvent(event, properties) ⇒ <code>Promise</code>
Track an event with certain metadata and properties about the user.

**Kind**: global function

| Param | Type | Description |
| --- | --- | --- |
| event | <code>String</code> | The name of the event to track. |
| properties | <code>Object</code> | Metadata to track about the event. |

<a name="trackException"></a>

## trackException(exception, fatal) ⇒ <code>Promise</code>
Track an exception event with the exception and
whether or not it was fatal as properties.

**Kind**: global function

| Param | Type | Description |
| --- | --- | --- |
| exception | <code>String</code> | The exception to track. |
| fatal | <code>Boolean</code> | Whether or not the exceptionw as fatal. |

<a name="trackPage"></a>

## trackPage(page) ⇒ <code>Promise</code>
Track a page event with the name of the page as a property.

**Kind**: global function

| Param | Type | Description |
| --- | --- | --- |
| page | <code>String</code> | The name of the page to track. |

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