Using tags to define user segments

The JavaScript commands to implement tags for user segmentation

If you are about to create your user segmentation, we recommend that you use custom data attributes. You can pass any user information within a custom attribute. Compared to tags, attributes provide more flexibility and data types. Learn more about adding custom fields to user attributes and user segmentation. If you still want to use tags for defining user groups, you can implement the following commands to tag and untag users. 

How it works 

Dev task: Implement your tags

A tag can be any string. However, we recommend limiting the length to 128 characters. You can use the following tag commands

// Tag Command
Userlane('tag', 'admin');

// Multiple Tags Command
Userlane('tag', 'admin', 'exampleTag', 'anotherOne');

// Remove Tags Command
Userlane('untag', 'myCustomTag');

// Remove Multiple Tags Command
Userlane('untag', 'myCustomTag', 'exampleTag', 'anotherOne');

// identify the current user
Userlane('user', 'user_ID');

Positioning and page reloads

  • Set all segmentation commands before you initialize Userlane with Userlane ('init', yourPropertyId);. The 'init' command only needs to be called once in your snippet after all segmentation commands in order to confirm the changes. In this way, Userlane will automatically adjust the assistant to reflect changes in the tags and in the segmentation. It is not necessary to call the 'init' command after each individual segmentation command.

  • The tags are not persistent across page reloads. On every page reload, the user starts with empty tags. This means you have to call the tag or untag command(s) after every page reload.

Manager Task: Create and apply your segmentation in the Userlane Dashboard

⇨ Start this Guide to learn how to create a user segment with the implemented tags.
⇨ Start this Guide to learn how to apply a user segment to a specific chapter/Guide.

Related articles