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.

Admin task

1. Share the snippet with your developers 

To locate the Userlane snippet, select Settings from your application dropdown, then select Setup in the left sidebar menu. 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 under General Settings to ensure that none of your users sees Userlane before go-live.

If you already have a Userlane Account and you would like to see this interactively:
⇨ Start this Guide to set chapters to private.
⇨ Start this Guide to switch off Userlane.

Developer tasks

1. Implement the snippet 

The load function loads Userlane in your application. The initialize command executes Userlane and is needed for the Userlane Assistant to appear. The Snippet should be implemented into the application's front-end, before the closing </body> tag.

// 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 Portal snippet. The initialize command executes Userlane. Therefore, all the commands that you want to additionally use should be called before ‘init’.

ℹ️  You need to load and initialize Userlane to make it visible in your application. Any other commands are optional.

2. Add additional user information in your code snippet

We recommend that you add 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');

ℹ️  We recommend that you use the user ID in the identify command as well. Keep in mind that if this command is not used, Userlane will generate a random user ID and will save it in a cookie.

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

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

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

ℹ️  If any additional commands are added in the snippet, make sure they are called before the initialize command. The initialize command confirms the passed user information. Therefore, whenever the page is reloaded, the passed user information is refreshed.