JavaScript Variables

Do you want to trigger optin campaigns using custom JavaScript variables?

Use custom JavaScript variables to create high-converting optin campaigns that are seen when, where, and exactly to whom you want. This not only leads to providing a better user experience (UX) across your site, but it also leads to more conversions and sales for you.

Get Total Control With JavaScript Variable Rules

Using our JavaScript variable rules to trigger a campaign is an advanced feature that you can use if you (or your developer) have a working knowledge of JavaScript.

javascript variable targeting

Whereas the HTML element lets you create A LOT of personalized triggers for your campaign, JavaScript variables literally make the options limitless.

In other words, if you or your developer understand and use JavaScript, you can literally make a trigger for anything on your website.

JavaScript Variable Rules for eCommerce

Adding JavaScript rules to your optin campaigns can do wonders for your online store. It can help business owners:

  • Make targeted product recommendations in the customer’s shopping cart
  • Reduce shopping cart abandonment with item-specific recommendations
  • Display campaigns based on user behavior
  • Personalize UX to display campaigns that your customers will find most interesting

If you know enough JavaScript, the sky really is the limit.

Now, in most cases, our native display rules will have you covered. But sometimes, you’ll want a custom trigger for more complex scenarios.

With OptinMonster’s JavaScript variable rules, online store owners have complete control how your optin campaigns function.

JavaScript Variable Rules for Online Publishers

The benefits of custom JavaScript variable rules aren’t exclusive to the world of eCommerce. You can also use JavaScript to customize your optin campaigns if you’re an online publisher or affiliate marketer.

As an example, let’s say you have infinite scroll JavaScript on your blog’s homepage. That means whenever the reader gets within 500px of the page’s footer, your JavaScript rule will fetch new article suggestions for your reader.

javascript variable rule

With OptinMonster, you can create a special rule to display your optin campaigns whenever a certain number of new post suggestions are loaded.

So when a user gets their first round of article suggestions, they’ll see a campaign related to the blog’s content. Then, when they get another round of article suggestions, they’ll see another targeted campaign (and so on).

That kind of campaign might look like this:

This leads to a more personalized UX which, in turn, gets you higher conversions.

Again, this is just one of the many use cases for this advanced feature, but there are many others. The point is that our JavaScript variable trigger gives you 100% control over your lead generation strategy.

And as a result, you can get higher conversions and drastically increase your profits.

Ready to get started targeting your audience and boosting conversions? Start your risk-free OptinMonster account today!

Effective Lead Gen Solutions Made Simple

OptinMonster’s drag-and-drop builder, simple but powerful triggers, and precise targeting make it easy to get started.

Easy Setup

Easily create and launch beautiful campaigns that are proven to convert in 5 minutes or less without needing a coder or designer!

Drag ‘n’ Drop Builder

Quickly create stunning campaigns using proven playbooks, ready to customize templates or your own custom design.

Page Level Targeting

Use behavior personalization to display page-specific campaigns based on each unique visitor’s interactions on your website.

Exit Intent Technology

Convert abandoning visitors into subscribers and customers at the precise moment they attempt to leave


Create a 2-step optin campaign from any link to improve lead generation and grow your email list fast. Proven to boost conversions by over 785%.

Smart Tags

Easily personalize your website with dynamic smart content for higher engagement and conversions.

OnSite Retargeting

Reduce abandonment and save money on external advertising by customizing promotions for returning visitors.

Smart Targeting Rules

Guide customers through your sales funnel by presenting new offers at each stage of their journey.

Advanced Scheduling

Run holiday promotions and other time-sensitive campaigns during specified periods, and display campaigns to visitors in their own time-zones.

Powerful Insights

Easily understand the metrics that matter and refine your lead generation strategy to boost your conversion rate.

Team Collaboration

Share access and manage permissions on your OptinMonster dashboard with coworkers, third-party consultants, or clients.

Easy A/B Testing

Make data-driven tests and decisions that will improve your conversions and revenue for any campaign.

Start Getting More Leads & Sales Today with OptinMonster!

Start Getting More
Leads & Sales Today
with OptinMonster!

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

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

In only 7 months, we added more than 95,654 names to our email list using OptinMonster’s Exit Intent™ technology. We strongly recommend it!

Michael Stelzner - Best Lead Generation Tool

Michael Stelzner

Founder Social Media Examiner

I hate popups, so I was hesitant to try one on my site. But the results from OptinMonster exit-intent popup speak for themselves. I doubled my subscription rate immediately without annoying my users. I haven’t had a single complaint. My only regret is that I didn’t start using OptinMonster sooner. I can only imagine how many subscribers I could have added to my email list! If you have a blog, then I highly recommend you start using OptinMonster. I’ve researched them all, and it’s the best in market.

Michael Hyatt - WordPress Lead Generation

Michael Hyatt

New York Times Bestselling Author Platform: Get Noticed in a Noisy World

Exit-intent popups have doubled my email opt-in rate. When done right, you can see an instant 12% lift on driving sales. I highly recommend that you use OptinMonster for growing your email list and sales.

Neil Patel - WordPress Popup Plugin

Neil Patel

Founder QuickSprout