Custom Attribute

1. When should you use custom attributes?

When you want to display your messages to one specific segment of your visitors. Custom attributes give you the power to base your audience segmentation on any variable you define.

This feature has been proven useful when there is additional information about your visitors that can be used to group them into different audience segments.

2. Why should I use custom attributes?

Custom attributes give you the ability to present highly-tuned messages to specific audience segments. The basis of the segmentation can be any variable you define. This feature has been proven to be useful if there is additional information about the visitors which you can base upon. For instance, an eCommerce site can use previous orders or items viewed as custom variables. These custom variables trigger specific messages related to those orders and items. This is an excellent way to encourage repeat business or generate buzz for a new product offering.

3. How do I set up my site for OptiMonk to retrieve my custom attributes?

OptiMonk retrieves data on custom attributes you define using JavaScript code. You define the custom attributes and their value within the JavaScript code and then place that code on your site.

4. What code do I need for OptiMonk to retrieve the data on my custom attributes?

The JavaScript code below should be inserted into the source code of your site to define the custom variable:

<script type="text/javascript">
    var OptiMonkOnReady = function () {
        var adapter = OptiMonk.Visitor.createAdapter();
        adapter.attr('variable_name', 'variable_value');

A real-life example could look like this:

<script type="text/javascript">
    var OptiMonkOnReady = function () {
        var adapter = OptiMonk.Visitor.createAdapter();
        adapter.attr('registered', 'yes');
        adapter.attr('hasorder', 'no');

In the example above two custom attributes have been defined:

  • "registered" and "hasorder"

with the values:

  • "yes" and "no"

After the JavaScript code has been executed by a visitor to your site, we save those values in the visitor’s browser. The value is stored here until we change it explicitly.

To remove a custom variable, use the following method:

<script type="text/javascript">
    var adapter = OptiMonk.Visitor.createAdapter();

5. Some important details to note when inserting the code

  • The name of the variables cannot include special characters
  • Variables are case sensitives
  • The OptiMonkOnReady function should be defined only once, i.e. - only one time per page.
  • OptiMonk.Visitor exists only if there is at least one active campaign on the domain

6. How do I set up my OptiMonk campaigns to use my custom attributes?

1. Log in to your OptiMonk account at

2. Select Campaigns on the left, then select the Campaign you want to use with custom attributes:


3. Click Edit settings on the right:


4. Click on Add new condition under Select who should see the popup:


5. Scroll down to Custom variable and click on the Add sign next to it:


You will see the available settings:


The following 4 parameters should be set up for each rule:

  1. The name of the variable
  2. The type of the variable: text or number.
  3. The method of comparison: equals, doesn’t equal, contains, doesn’t contain, is set, isn’t set
  4. Which value it should be compared to

The value of [named] variable, which is a text, equals yes.


6. Once you are ready, click on Save and Next in the top right corner to save your settings.

That's it! :) If you have any further questions or need any help, please contact us at, we would be happy to assist you :)

Have more questions? Submit a request