0.1.2 • Published 8 months ago

analytics-forwarder v0.1.2

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

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

getFingerprint() ⇒ Promise

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: Promise - A promise with the fingerprint.

getKey() ⇒ Promise

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: Promise - A promise with the tracking key.

setUser(id, bearerToken) ⇒ Promise

Set the current user to track and identify the user in the analytics.

Kind: global function

ParamTypeDescription
idStringThe id of the user to track.
bearerTokenStringThe bearer token for the user for non public tracking.

trackEvent(event, properties) ⇒ Promise

Track an event with certain metadata and properties about the user.

Kind: global function

ParamTypeDescription
eventStringThe name of the event to track.
propertiesObjectMetadata to track about the event.

trackException(exception, fatal) ⇒ Promise

Track an exception event with the exception and whether or not it was fatal as properties.

Kind: global function

ParamTypeDescription
exceptionStringThe exception to track.
fatalBooleanWhether or not the exceptionw as fatal.

trackPage(page) ⇒ Promise

Track a page event with the name of the page as a property.

Kind: global function

ParamTypeDescription
pageStringThe name of the page to track.
0.1.2

8 months ago

0.1.1

10 months ago