JavaScript NPM
JavaScript NPM Setup
This SDK is for client-side events from a Javascript front end. For server-side events, use the Node.js SDK.
1. NPM install
Run this in your CLI to install the Sumatra SDK.
npm install @sumatra/sdk-js
2. Load the Sumatra SDK
Add the following code to load the Sumatra SDK, using your private API Key.
import * as sumatra from '@sumatra/sdk-js';
sumatra.load("ak_0ae327050e02","https://api.sumatra.ai");
3. Track your first event
Add event-tracking code like the example below to any event you want to track.
sumatra.track('add_to_cart', {
my_first_attribute: 'KS944RUR',
another_attribute: 9.99
})
Tip
Start by tracking only one or two events. You can always add more later.
4. Later, fetch enrichments
When you are ready to use Sumatra to fetch features or take an action in your application,
add an enrich
call. An enrich
call is used to both track and enrich events, so it may replace a track
call you previously added.
The following example logs the output to the console.
sumatra.enrich('purchase', {
payment_method: 'visa',
total: 99.99
}).then((enriched) => {
console.log(enriched)
})