How to implement the Userlane snippet

This article describes the steps required to implement the different parts of the Userlane snippet into your application code.

Manager task

1. Share the snippet with your developers 

Locate your Userlane snippet in the Dashboard by going to My Account > Snippet. Copy the snippet and send it to your developers. 

The snippet makes Userlane visible for your end-users. You can simply set all chapters to private or switch Userlane off in the Userlane Dashboard to ensure that none of your users sees Userlane before go-live.
⇨ Start this Guide to set chapters to private.
⇨ Start this Guide to switch off Userlane.

Developer tasks

1. Implement the basic snippet parts

The load function loads Userlane in your application. The initialize command executes Userlane and is needed for the Userlane Assistant to appear. 

// load Userlane
(function(i,s,o,g,r,a,m){i['UserlaneCommandObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)};a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','https://cdn.userlane.com/userlane.js','Userlane');

// identify your user (see Chapter 3. below)

Userlane('identify','user_ID');

  
// initialize Command

Userlane('init', your_property_ID);

Make sure that the initialize command contains your account’s property ID that can be found in the Userlane Dashboard Snippet. 

The initialize command executes Userlane. Therefore, all the commands you want to use additionally should be called before ‘init’.

2. Pass additional user information in your code snippet

We recommend that you pass the user ID in your snippet with the identify command so that Userlane can save the status of a user anonymously. 

// Pass the user ID without any Custom User Attributes

Userlane('identify','user_ID');

Additionally, you can pass Custom User Attributes within this command. This allows applying user-based segmentation in the Userlane Dashboard later. This article provides more info on how a Snippet with passed custom data attributes looks like. 

// Pass a Custom User Attribute (data types: number, string, datetime, array, boolean)

Userlane('identify','user_ID',{
  Attribute_key:'Attribute_value'
});

Good to know

  • You need to load and initialize Userlane to make it visible in your application. Any other commands are optional. However, we recommend passing the user ID in the identify command as well. If this command is not used Userlane will generate a random user ID and will save it in a cookie.

  • If you pass any additional commands in the snippet, make sure they are called before the initialize command. The initialize command will confirm the passed user information. Therefore, with every reload, the passed user information refresh.