OptinMonster Documentation

Documentation, Reference Materials, and Tutorials for OptinMonster

Home

Docs

How to Use OptinMonster’s JavaScript Variables Rule

How to Use OptinMonster’s JavaScript Variables Rule

OptinMonster makes it easy to hide or show campaigns based on a JavaScript variable in the page the campaign is loading on.

In this article, you’ll learn how to use OptinMonster’s Display Rules to hide or show a campaign based on a JavaScript variable.

Before you start, this feature is available with a Pro and higher subscription.

The JavaScript variable needs to be declared on a global scope (ie. window.customJSVariable), or it will not be detected.

Configure JavaScript Variables Rule

When you create a campaign in OptinMonster you can configure it to be shown or hidden based on a JavaScript variable in the page.

To configure the JavaScript variables rule, follow these steps:

  1. Navigate to the Display Rules view in the campaign builder.
    Navigate to the Display Rules in the OptinMonster campaign builder.
  2. Next, when adding or editing a rule select Who (Personalization) from the left-hand list and select the JavaScript Variable Targeting option.
    Select the JavaScript Variable Targeting rule.
  3. Configure the rule as desired using the operator dropdowns, and key and value fields.
    Configure the JavaScript Variable Targeting rule.
    The following options are available for JavaScript Variable Targeting:
    • exactly matches
    • does not exactly match
    • contains
    • does not contain
    • starts with
    • does not start with
    • ends with
    • does not end with
    • is anything (if the key or value is irrelevant, choose this option)
    • matches the pattern
    • does not match the pattern
  4. When you’re finished, Save the campaign.

Examples

The following are some examples to help you get started:

Simple Variables

If I entered myJavaScriptVariable as my key, and testValue as my value, the rule will only pass when it is able to find a global JavaScript variable named myJavaScriptVariable that has a value of testValue.

JavaScript Variables rule example.
Complex Variables

Users can chain together more complex variables, such as an object.

For instance, if my key was globalObj.test1.test2.test3.testVar, the rule will look for window.globalObj, then loop through each section of the JavaScript object to find testVar.

If the string is improperly formed, has a syntax error, or the variable path is incorrect, the rule will fail.


If you’re serious about jumpstarting your website business growth, then get started with OptinMonster today!

Get Started With OptinMonster Today!

BONUS: Done-For-You Campaign Setup ($297 value)

Our conversion experts will design 1 free campaign for you to get maximum results – absolutely FREE!

Click here to get started →


Still stuck?

How can we help?

Last updated on


Start Getting More
Leads & Sales Today
with OptinMonster!

Create and launch smart capture forms today in minutes. What are you waiting for?

Create and launch smart capture forms
today in minutes. What are you waiting for?

OptinMonster has transformed our business. Before integrating their optins, our clients saw a 2% conversion rate from web traffic, which is slightly above the standard for their industry. With the integration of OptinMonster’s lightbox popup, exit-intent technology, split testing, and other tools, our client’s conversion rates soared by an unprecedented 500%. They attracted substantially more customers while spending less on digital advertising. Their success propelled them to the top of their markets, outperforming national chains and other medical spas with much bigger marketing budgets. Our client’s success in their market has distinguished us in our own. We are now one of the most sought-after marketing firms in the industry of aesthetic medicine. We know that the integration of OptinMonster, more than any other tool or marketing strategy, has supported this growth and achievement.

chris zelig medstar media

Chris Zelig

Partner, Medstar Media

OptinMonster has been a game-changer for us. From driving donations to collecting new leads, there is nothing that this simple tool has failed to accomplish. Our lead collection rate has jumped by over 1,000%.

joe lowe american bird conservancy

Joe Lowe

Director of Digital Communications, American Bird Conservancy

Through OptinMonster’s exit-intent popups, we have more than doubled our sales conversion rate. Best of all is the compound effect of using OptinMonster over a long period of time—more conversions mean more customers, which means more word of mouth.

mitch smith, managing director, shockbyte

Mitch Smith

Managing Director, Shockbyte.com