Vitally.js is a small Javascript library that allows you to directly send us data about your users and their product usage. 

How to Install

Copy the code below and paste it into your product, right before the closing </body> tag. You'll need to add your own unique token to the below Vitally.init call. You can grab your token in the Integrations section of your Account Settings.

<script type="text/javascript" src="https://cdn.vitally.io/vitally.js/v1/vitally.js" defer></script>
<script type="text/javascript">
  !function(n,t,r){for(var i=n[t]=n[t]||[],o=function(r){i[r]=i[r]||function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];return i.push([r,n])}},u=0,c=["init","user","account","track"];u<c.length;u++){o(c[u])}}(window,"Vitally");
  Vitally.init('YOUR_TOKEN_HERE');
</script>

Once you install the script in your product, a Vitally API will be attached to the global window object.

Identifying the logged-in account & user

 After you've installed the script, then once the user is logged in, you should identify both the user AND the account the user belongs to.

Vitally.account

Vitally.account allows you to identify the business account (i.e. organization) using your product. It is recommended to call this API first, before Vitally.user.

Vitally.account({
  accountId: 'account-id', 
  traits: { 
    name: "Bob's Burgers",
    // Add any other traits here you'd like to attach to your accounts in Vitally
  }
});

Vitally.user

Vitally.user allows you to identify the user at the account that is currently using your product.

Vitally.user({
  userId: 'user-id', 
  accountId: 'account-id', 
  traits: { 
    name: 'Bob Belcher',
    email: 'bob@bobsburgers.com',
    // Add any other traits here you'd like to attach to your users in Vitally
  } 
});

Sending 'account-id' is optional if you've already called Vitally.account, but if possible, it is always best to be explicit.

// Only do this id you've called Vitally.account first
Vitally.user({
  userId: 'user-id',  
  traits: { 
    name: 'Bob Belcher',
    email: 'bob@bobsburgers.com',
    // Add any other traits here you'd like to attach to your users in Vitally
  } 
});

Vitally.track

Vitally.track allows you to track the interactions the user has with your product.

Vitally.track({
  event: 'help-option-clicked', 
  userId: 'user-id',
  properties: { 
    option: 'chat',
    // Add any other properties here you'd like to attach to the event in Vitall
  }
});