JavaScript Snippet Setup
1. Add JS snippet
Copy-paste this snippet in the <head>
section of your site or app:
<script type="text/javascript">
!function(){var sumatra=window.sumatra=window.sumatra||[];sumatra.methods=["load","track","enrich","ready","registerAnalyticsSource"],sumatra.factory=function(t){return function(){sumatra.push([t].concat(Array.prototype.slice.call(arguments)))}};for(var t=0;t<sumatra.methods.length;t++){var r=sumatra.methods[t];sumatra[r]=sumatra.factory(r)}sumatra.loadJS=function(e,t){var r=document.createElement("script");r.type="text/javascript",r.async=!0,r.src="https://cdn.sumatra.ai/v1/sumatra-sdk.min.js";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(r,a)},sumatra.loadJS(),
sumatra.load("SUMATRA_API_KEY", "https://api.sumatra.ai")
}();
</script>
Important
Replace SUMATRA_API_KEY
with your private API key.
Or if you use Google Tag Manager, follow these instructions.
2. Start tracking events
The JS snippet will not send events to Sumatra on its own. Instead, you send events and their attributes by adding event-tracking code like the example below:
window.sumatra.track('add_to_cart', {
my_first_attribute: 'foo@bar.com',
another_attribute: 9.99
});
The function may be placed anywhere you'd like, but is typically called from a callback or event handler in your application.
Tip
Start by tracking only one or two events. You can always add more later.
3. 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.
window.analytics.enrich('purchase', {
my_first_attribute: 'foo@bar.com',
another_attribute: 9.99
}).then((enriched) => {
console.log(enriched)
});
The enriched
response object will contain all of the features
computed by your Scowl code. See the API response docs for the full details.
Or — let an expert do it
A Sumatra expert will set up your data integration and workspace at no cost to you: