Skip to main content

Analytics SDK - JavaScript

Overview

The Snowplow JavaScript and TypeScript Analytics SDK lets you work with Snowplow enriched events in your JavaScript event processing, data modeling and machine-learning jobs. You can use this SDK with AWS Lambda, Google Cloud Functions, Google App Engine and other JavaScript-compatible frameworks.

Setup

Install using your preferred package manager, such as npm:

npm install --save snowplow-analytics-sdk

Usage

Overview

The Snowplow JavaScript and TypeScript Analytics SDK provides you an API to parse an enriched event from it's TSV-string form to a JSON string.

Example

To consume in an AWS lambda you would do something like this in your app.js:

const { transform } = require('snowplow-analytics-sdk');

module.exports.handler = (input) => {
let event = transform(
new Buffer(input.Records[0].kinesis.data, 'base64').toString('utf8'),
);

// ...
};

Or in app.ts:

import { transform } from 'snowplow-analytics-sdk';

export function handler(input: any) {
let event = transform(
new Buffer(input.Records[0].kinesis.data, 'base64').toString('utf8'),
);

// ...
}

API

transform(event: string): Event

  • event: string - TSV string containing event data.

Returns decoded Snowplow enriched event.