Vitally's Javascript SDK (Vitally.js)

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

Vitally.js is just one of the ways you can send your customer data to Vitally. Check out all our integrations if you'd rather integrate one of your existing tools into Vitally.

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 -> Vitally API section of your Account Settings (get there via Quick Jump).

<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", // required
    avatar: "https://my-images.com/an-image", // optional, but makes Vitally look prettier :)
    // 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', // Sending accountId is optional if you've already called Vitally.account, but it's always best to be explicit :)
  traits: { 
    name: 'Bob Belcher',
    email: 'bob@bobsburgers.com',
    avatar: "https://my-images.com/an-image", // optional, but makes Vitally look prettier :)
    // 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
  }
});

By default, Vitally will associate the track to the account the user was last associated to. If Users are associated to multiple Accounts, using all three of the above calls in the order listed is recommended to ensure the track is associated to the proper account.

Last updated