JS Tracking Library

Data can be sent to Accoil via a JavaScript tracking library.

The library has no dependencies. To include it in your site, simply add the following snippet:

<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>

To use the library, you must first set your API key. For example, if your API key was f7d504aa5a384372ba30aa4e7db8d162, you would use the following JavaScript call:

accoil.load("f7d504aa5a384372ba30aa4e7db8d162");

You should set up this Accoil library in your top-level template; the same place you add the snippet:

<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(apiKey);
</script>

Identify Calls

The .identify call allows you to identify the users navigating through and using your application. This is a required step before tracking any user activity.

Using the .identify call is simple. As an example, if the user is john@example.com, you would call:

accoil.identify("{userID}");

You can optionally assign user traits when identifying the user:

accoil.identify("1234", {
  first_name: "John",
  paid_user: true,
  plan_type: "Enterprise",
  created_at: "2019-03-27T01:20:00Z"
});

When to make .identify call

You should make an .identify call upon every page load to ensure that your user actions will be assigned correctly. You should set up the Accoil library in your top-level template - the same place you add the snippet:

<script type="text/javascript">
  // snippet goes here
</script>
<script type="text/javascript">
  accoil.load(apiKey);
  accoil.identify(userID, {...traits...});
</script>

The library keeps track of the current user on the page. Once a user is identified, all subsequent .track calls will be scoped to that user.

Group Calls

The .group call is designed to allow you to organize your users into groups - (ie - accounts) - and record custom traits to those accounts (ie - MRR, Plan_type, Industry, etc).

This call is very important if you want to organize, score, and segment your SaaS accounts in Accoil.

Users can be assigned to a group with:

accoil.group('{GroupID}');

Group traits can be set using:

accoil.group('12345', {
  name: "Nike"
  status: "active",
  mrr: 1000
});

When to make .group call

Just like with an .identify call, you should make your .group calls when a new account is created or whenever any significant change in account information or status, for example:

  • Conversion from trial to paid
  • Upgrade/Downgrade
  • Cancellation
  • Change of location
  • Etc.

Track Calls

The .track call is used to send user event data to Accoil. Once a user has been identified, you can begin tracking events, using:

accoil.track("Login");

So long as you have the Accoil library set up correctly in your top-level template, then you don't have to include a userID with any .track calls. The library will automatically assign and .track event to the identified user.