Adding custom fields to user attributes

Custom data are fields that you can add as user attributes to your user profiles. They can be filled with data. This data will help you to build better user segments that allow you to target specific user groups.

Before you proceed, make sure you’ve already planned and created all custom data fields that you will need.

The JavaScript snippet

Userlane is loaded up via a JS snippet already. This JS snippet is the foundation. You can amend the JS snippet of Userlane to save data in the user profile of the current user. This happens with the identify command in the snippet:

Userlane('identify',, {
  attribute_key: 'attribute_value'

Example snippet:

// 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','','Userlane');

// TODO: the command below is just for illustration purposes
// it's definition must be changed to work for your application
var currentUser = please_replace_this_with_your_api_call.getCurrentUser(); // returns an object with id and other data of the current user who’s using the application in this moment

// identify the user for Userlane
Userlane('identify',, {

 // TODO: these fields below are defined by you.
 // Below are just examples. You must individually customize
 // your own attributes and variables here.
 permissions: currentUser.permissions

// initialize Userlane with your account ID, in this example it is “12345”
Userlane('init', 12345);

Your individual JS Snippet

You will find an example tailored to your setup in your Portal.

Custom field data types

Every custom field has a data type. It can only accept data that fits this type. These types are defined when the custom data field is first created and can not be changed afterward.

Supported data types:

1. True/false: Custom true/false fields accept JavaScript booleans. We also parse values like 1, 0, “yes” and “no” to their respective true/false value.  


Userlane('identify',, {
  is_admin: true

2. Text: Custom text fields accept JavaScript strings. There is no length limit on individual strings but all custom data may not exceed the size of 500kb.


Userlane('identify',, {
  description: 'Some text description'

3. Number: Custom number fields accept JavaScript numbers, both integers and decimals/floats.


Userlane('identify',, {
  store_number: 224

4. Date and time: Custom date and time fields accept strings that represent a timestamp in any of these formats:


2017-04-28 20:12:55







yyyy-mm-dd hh:mm:ss

2020-02-20 23:42:51

yyyy/mm/dd hh:mm:ss

2020/02/20 23:42:51




Userlane('identify',, {
  date_created: '2020/02/20 23:42:51' 

5. List: Custom list fields accept JavaScript arrays. We only accept string and integer elements in the array. The order of the elements in the array is not considered. When a new array is provided, we’ll override the previous array entirely.


Userlane('identify',, {
  roles: ['admin','editor','user']

In case of the list, if you create a segment that has the logic EQUALS, it will not work with just one item from the list. EQUALS in this case means all items in the list.

ℹ️ An Attribute that is passed via the snippet but has not been set up in the Portal will be ignored by Userlane. This also applies to Attributes that have a different name in the snippet and in the Portal. 

Related Articles

Do you need more information?

If you have a Userlane account, please contact our Customer Success Team.

User Icon

Thank you! Your comment has been submitted for approval.