Quick Start: JavaScript SDK
Add Accoil tracking to your browser app in under 5 minutes.
This guide walks you through installing the Accoil JavaScript SDK and making your first identify, group, and track calls from a browser application.
Prerequisites
You need an active Accoil account and an API key. Find your key under Account > General in the Accoil dashboard. Each product has its own key.
Step 1: Add the snippet
Paste the following into your HTML <head> or top-level template. This loads the Accoil SDK asynchronously with no dependencies.
<script type="text/javascript">
(function() {
var accoil = window.accoil = window.accoil || {q: []};
var calls = ['load', 'identify', 'group', 'track'];
for (var i = 0; i < calls.length; i++) (function(call) {
accoil[call] = function() { accoil.q.push([call, arguments]); };
})(calls[i]);
var s = document.createElement('script');
s.src = 'https://cdn.accoil.com/tracker.js';
s.async = true;
var f = document.getElementsByTagName('script')[0];
f.parentNode.insertBefore(s, f);
})();
</script>The snippet queues calls made before the library finishes loading, so you can safely call SDK methods immediately.
Step 2: Load with your API key
Initialize the SDK with your product API key. Place this right after the snippet.
<script type="text/javascript">
accoil.load("YOUR_API_KEY");
</script>Step 3: Identify the user
The identify call tells Accoil who the current user is. Call it on every page load after the user logs in.
accoil.identify("user_12345", {
email: "jane@example.com",
name: "Jane Doe",
created_at: "2025-03-15T10:00:00Z"
});Once identified, all subsequent track calls are automatically scoped to this user.
Step 4: Group the user to an account
The group call associates the current user with an account. This is how Accoil builds account-level engagement data.
accoil.group("account_456", {
name: "Acme Corp",
plan: "pro",
mrr: 50000
});Send group traits like name, plan, status, and mrr to power segmentation and health scoring in Accoil.
Step 5: Track events
The track call records a user action. Pass only the event name -- Accoil does not accept event properties.
accoil.track("Report_Created");Call track whenever a user performs a meaningful action: creating content, enabling a feature, inviting a teammate, and so on.
Complete example
Here is the full setup in a single template:
<script type="text/javascript">
(function() {
var accoil = window.accoil = window.accoil || {q: []};
var calls = ['load', 'identify', 'group', 'track'];
for (var i = 0; i < calls.length; i++) (function(call) {
accoil[call] = function() { accoil.q.push([call, arguments]); };
})(calls[i]);
var s = document.createElement('script');
s.src = 'https://cdn.accoil.com/tracker.js';
s.async = true;
var f = document.getElementsByTagName('script')[0];
f.parentNode.insertBefore(s, f);
})();
</script>
<script type="text/javascript">
accoil.load("YOUR_API_KEY");
// Identify the logged-in user
accoil.identify("user_12345", {
email: "jane@example.com",
name: "Jane Doe",
created_at: "2025-03-15T10:00:00Z"
});
// Associate them with an account
accoil.group("account_456", {
name: "Acme Corp",
plan: "pro",
mrr: 50000
});
</script>Then call accoil.track("Event_Name") anywhere in your application code when user actions occur.