The Userlane Javascript API provides some events that you can hook into. This allows you to get notified when a user does something within Userlane.

There are 3 events that you can listen to:

  1. onStart is fired after a user started a guide.
  2. onComplete is fired after a user successfully completed a guide at its last step.
  3. onExit is fired after a user canceled a guide or the guide was canceled because of an error.

Hooking into events

All three of those events work with the same structure:

// hook into onStart and provide a callback function
Userlane('onStart', function(userlaneId, user) {

// you can put any code in here

console.log('the user started a guide');
});

Use the event name as the first argument and provide a callback function in the second argument. This callback function will be called with two arguments:

  1. userlaneId is a unique identified for the userlane that triggered the event
  2. user is the object with all the data about the user we have at this point. You can assume that it always has an id  attribute.

onStart - after a user started a guide

This event is fired whenever a guide is started, even if the guide is started from the API's start command.

// hook into onStart and provide a callback function
Userlane('onStart', function(userlaneId, user) {

// you can put any code in here

console.log('the user started a guide');
});

onComplete - after a user successfully completed a guide at its last step

This event is fired whenever a user reached the end of a guide. This indicated that the guide was completed successfully. From now on, the guide will be marked with a green checkmark in the Userlane Assistant for this user.

// hook into onComplete and provide a callback function
Userlane('onComplete', function(userlaneId, user) {

// you can put any code in here

console.log('the user completed a guide');
});

onExit - a user canceled a guide

This event is fired whenever a user cancels a guide using the cross in the guide step. It is also fired when a guide cancels itself after an error or when an important step is not found.

// hook into onExit and provide a callback function
Userlane('onExit', function(userlaneId, user) {

// you can put any code in here

console.log('the user canceled a guide');
});

Overwriting callbacks

We only keep one callback for each event. If you hook up to an event again, it will overwrite your previous hook.

Removing callbacks

If you want to unbind a callback from these events, call the event name again with false, null, or undefined instead of a callback function.

// remove all callbacks from the onStart event
Userlane('onStart', false);

The user object

The second argument passed to your callback function is the user object. It contains all the data we have about the user at the time of the event. It is guaranteed that the user at least has an id.

Additionally to the id we provide the flag generated  that tells whether the id was randomly generated by Userlane or whether it was provided to our API or Snippet.

An example for the user object is 

{
id: "9717166719265375",
generated: true,
time_signup: "2017-11-22T11:50:48.671Z"
}

Get creative!

By hooking into these events you can build powerful integrations with other tools. For example, you could forward those events to your analytics solution to correlate them with all the other data you have there.

These events are also useful if you want to trigger other reactions to the activity of your users in userlane.

Do you need more info?

Contact us via our Intercom Chat or write us a message at support@userlane.com.

Did this answer your question?