Javascript Library

Our Javascript Library is our most full-featured library and is what we recommend for most users. It has extra provisions for things like automatically handling identities and aliasing, tracking common web events and running A/B tests.

Head over to the Setup to access your tracking snippet.

The JavaScript library loads asynchronously, in the background, just like Google Analytics’ Asynchronous Tracking. Asynchronous loading does not affect your page’s load times. It is also compatible with pages served using both HTTP or HTTPS. The // before the path of your JS files is a protocol-independent absolute path, which detects whether your site uses HTTP or HTTPS.

You can place the JavaScript snippet anywhere in the HTML document, but we ask that you place the JavaScript snippet in the <head> to let our script load as soon as possible, to be able to send events before the visitor leaves. This also lets you queue events to be triggered when the library finishes loading. This prevents JavaScript errors from cropping up if you try to call events before the script has loaded: ReferenceError: _kmq is not defined.


Calling a Kissmetrics Function

All function calls (identify, record, set, etc.) and their arguments are passed as an array to the _kmq.push(fnArray) method. The first element of fnArray is the function to be called and the following elements are arguments to be passed to that function. For example:

_kmq.push(['identify', '[email protected]']) // Identify call


Javascript Library Examples

We have documented most examples using Codepen which you can use to try out our Javascript Library. Codepen is a front-end playground that allows users to interact with code as they use it. We use it in editor mode which will enable you to follow the steps on the screen and copy and paste code to get an example Intercom app installed on the page.