Custom Variable Targeting
Display campaigns based on any custom visitor data such as their name provided during the time of registration.
Custom Variable Targeting is an OptiMonk targeting feature — built on the Custom Attribute rule — that lets you show or hide campaigns based on any data point your website already knows about a visitor, passed to OptiMonk through a small JavaScript snippet in your site's source code. Where standard OptiMonk targeting rules work with data OptiMonk collects itself (cart contents, page URL, visit count, browser language), Custom Variable Targeting lets you bring in data from your own systems: whether a visitor is logged in, their registered first name, their loyalty tier, the number of previous orders they have placed, the last product category they browsed in a previous session, or any other custom property your site stores about its users. You define the variable name and its value in a JavaScript snippet using the OptiMonkOnReady function and OptiMonk.Visitor.createAdapter(), place that code on your site, and OptiMonk reads and stores the values in the visitor's browser. Once stored, those values can be used in campaign targeting conditions — with text and number operators including equals, contains, starts with, ends with, greater than, less than, and their negations — and also as Dynamic Text variables inside campaign copy, inserting the visitor's name or any other attribute directly into the popup text. Multiple custom attribute conditions can be combined with AND or OR logic within a single rule.
Key benefits
- Target campaigns using data your own platform already has about each visitor. Your ecommerce platform, CRM, and authentication system know far more about each visitor than OptiMonk can infer from behavior alone — their account status, their tier, their order history, their stored preferences. Custom Variable Targeting bridges that gap: by passing any of those properties to OptiMonk via JavaScript, you can create targeting segments that are impossible with standard rules, such as "show only to logged-in customers with more than 3 previous orders" or "show to visitors whose registered loyalty tier is Gold."
- Use the same variable for both targeting and Dynamic Text personalization. A custom attribute passed to OptiMonk serves double duty: it can gate which visitors see a campaign (targeting), and it can populate text within the campaign itself (Dynamic Text). A visitor's first name stored as a custom attribute can both trigger a returning-customer campaign and appear in the popup headline as "Welcome back, [Name]" — all from the same variable, with no additional configuration. This combination produces the highest-relevance popup experience possible from a personalization standpoint.
- Any data your site can express in JavaScript is a valid targeting signal. The custom attribute system imposes no constraint on what the variable represents — only that it can be expressed as a string or number in JavaScript. Previous order count, subscription status, last viewed product category, account creation date, membership tier, form submission flag — all are valid. If your site tracks it, OptiMonk can use it for targeting, making Custom Variable Targeting the most open-ended and extensible targeting condition in the platform.
How it works
Add the following pattern to your site's source code on pages where the variable is available — typically inside a template that runs when a visitor is logged in or after their session data is loaded: <script type="text/javascript"> var OptiMonkOnReady = function() { var adapter = OptiMonk.Visitor.createAdapter(); adapter.attr('registered', 'yes'); adapter.attr('name', 'Jane'); }; </script> Each adapter.attr() call defines one variable by name and value. OptiMonk stores these values in the visitor's browser after the code executes. The OptiMonkOnReady function should be defined only once per page, and OptiMonk.Visitor is only available when at least one active campaign exists on the domain.
In your campaign's targeting settings, click Add new rule and select Custom Attribute. Enter the variable name you defined in step 1 (for example, registered), choose the data type (text or number), select a matching operator (equals, does not equal, contains, starts with, ends with, greater than, less than, etc.), and enter the expected value (for example, yes). Add additional attribute conditions using AND logic (the Plus icon) or OR logic (the Add new button).
When the campaign trigger fires for a visitor, OptiMonk reads the custom attribute values stored in that visitor's browser and checks them against your conditions. If they match, the campaign displays; if not, it is suppressed. Values persist in the visitor's browser until explicitly updated or removed via adapter.removeAttr() in your JavaScript — so attributes set on one page remain available on subsequent pages and visits.
Frequently asked questions
What is Custom Variable Targeting in OptiMonk?+
Custom Variable Targeting is an OptiMonk targeting condition — the Custom Attribute rule — that shows or hides campaigns based on custom data points you define about each visitor and pass to OptiMonk through a JavaScript snippet on your site. Any property your website knows about a visitor — login status, name, order count, loyalty tier, last product category viewed — can be passed as a named variable and used to target campaigns precisely, either alone or combined with other conditions using AND/OR logic.
How does OptiMonk receive custom variable data from my site?+
You add a JavaScript snippet to your site's source code using the OptiMonkOnReady function and OptiMonk.Visitor.createAdapter(). Inside this function, you call adapter.attr('variable_name', value) for each custom property you want to pass. When a visitor loads the page and the script executes, OptiMonk captures and stores those values in the visitor's browser. The values persist across subsequent pages and sessions until explicitly removed or updated via adapter.removeAttr('variable_name').
Can I use custom variables in campaign copy as well as for targeting?+
Yes. Custom attributes can be used both as targeting conditions (to control who sees the campaign) and as Dynamic Text variables inside the campaign copy (to display the attribute value in the popup text). To insert a custom attribute into your campaign copy, use the placeholder format [[attribute:variable_name|default_value]] — for example, [[attribute:name|Visitor]] will display the visitor's stored name, or "Visitor" if no value is stored. This is how personalized greetings like "Welcome back, Jane" are produced.
What matching operators are available for custom attribute conditions?+
For text-type custom attributes, available operators include: equals, does not equal, contains, does not contain, starts with, does not start with, ends with, does not end with, and exists/does not exist. For number-type custom attributes, operators include: equals, does not equal, greater than, less than, and their combinations. Multiple conditions can be combined within a single Custom Attribute rule using AND logic (the Plus icon) or OR logic (the Add new button), and mixed AND/OR combinations are supported.
Are there any restrictions on custom variable names or values?+
Yes. Variable names cannot contain special characters — use only letters, numbers, and underscores. The OptiMonkOnReady function must be defined only once per page; defining it multiple times will cause the later definitions to overwrite earlier ones. Additionally, OptiMonk.Visitor is only available when at least one active campaign exists on the domain — if no active campaigns are running, the adapter will not be available, so the script should account for this if needed.
Try OptiMonk for free
Launch your first campaign, learn what works, then scale what converts.