Skip to main content
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.

Laura Bedoya avatar
Written by Laura Bedoya
Updated over 3 months ago

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

Navigate to your NPS settings within your Vitally by navigating to your Settings (βš™οΈ) selecting your Account Logo on the top left and under Vitally Objects select Surveys. Then select NPS (or via Quick Jump Mac: ⌘ + j Windows: Alt + j).

Copy your unique Javascript snippet from that page and paste it into your product right before the closing </body> tag. You can also use the snippet below, but you must add your own unique token and subdomain to the placeholders AND have the Organization level hierarchy enabled. We recommend copying your unique Javascript snippet from the NPS page above where authorization information will be automatically populated.

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

Vitally.init('YOUR_TOKEN_HERE','https://{subdomain}.api.vitally.io/analytics/v1');
</script>


You can grab your token by navigating to the Integrations page within Settings (get there via Quick Jump) and clicking on the Vitally Analytics API integration.

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

Identifying the logged-in User & Account or Organization

After you've installed the script, then once the user is logged in, you should identify both the user AND one or both of the Organization and Account the user belongs to.

Vitally.organization

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

Vitally.organization({ 
organizationId: 'UNIQUE_ORGANIZATION_ID', // A unique ID assigned by your codebase to each Organization (i.e. a database ID)
traits: {
name: "Pied Piper Global", // A 'name' trait is required
industry: "Disruptive software", // An example extra trait - this is not required
// Add any other traits here you'd like to attach to your Organizations in Vitally } });

Vitally.account

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

Vitally.account({
accountId: 'UNIQUE_ACCOUNT_ID', // A unique ID assigned by your codebase to each Account (i.e. a database ID)
organizationId: 'UNIQUE_ORGANIZATION_ID', // Same ID used in Vitally.organization above - used to associate the Account to the Organization
traits: {
name: "Pied Piper", // 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: 'UNIQUE_USER_ID', // A unique ID assigned by your codebase to each user (i.e. a database ID)
accountId: 'UNIQUE_ACCOUNT_ID', // Same ID used in Vitally.account above - used to associate the user to the Account
organizationId: 'UNIQUE_ORGANIZATION_ID', // Same ID used in Vitally.organization above - used to associate the user to the Organization
traits: {
name: 'Richard Hendricks',
email: 'richard@piedpiper.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 Vitally
}
});

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 four of the above calls in the order listed is recommended to ensure the track is associated to the proper customer.

Did this answer your question?