OptinMonster JavaScript Events API

The OptinMonster JavaScript Events API is extremely powerful, providing the tools needed to further extend OptinMonster to suit your specific needs.

   All JavaScript events are asynchronous
   All campaign IDs should use your campaign’s Unique ID

Use [TOP]

It’s that simple! You can now run your desired actions within the specified event.


What’s Available [TOP]

The following will give you all information about the campaign, as well as access to public JS methods for the campaign.

The event object passes information about the event and the OptinMonster campaign. You can then access those properties within your function.


Events associated with initializing OptinMonster [TOP]

om.Api.init [TOP]

Runs once per page when the API starts.


om.Main.init [TOP]

Runs once before campaigns are requested.


om.Main.parseCampaigns [TOP]

Runs once after campaigns are retrieved.


Events associated with initializing a Campaign [TOP]

om.Campaigns.init [TOP]

Runs once after the document DOM is ready, when campaigns object is initialized, but before the individual campaigns are initialized.


om.Types.init [TOP]

Runs while campaign is initializing and happens after initializing the campaign type object.


om.Analytics.init [TOP]

Runs while campaign is initializing and happens after initializing the Analytics object.


om.Sites.init [TOP]

Runs while campaign is initializing and happens after initializing the Sites object, but before the sites are matched against the current campaign.


om.Html.init [TOP]

Runs while campaign is initializing and happens after initializing the Html object, and, if applicable, before the campaign holder element is attached to the DOM.


om.Iframes.init [TOP]

Runs while campaign is initializing and happens after initializing the Iframes handler object.


om.Listeners.init [TOP]

Runs while campaign is initializing and happens after initializing the Listeners object, but before the event listeners are added.


om.Lock.init [TOP]

Runs while campaign is initializing and happens after initializing the Lock content-locking handler, but before locking/unlocking happens.


om.SoundEffects.init [TOP]

Runs while campaign is initializing and happens after initializing the SoundEffects object, but before any sound-effects are played.


om.Tags.init [TOP]

Runs while campaign is initializing and while initializing the Tags smart-tags handler, but before the tags are replaced.


om.Dtr.init [TOP]

Runs while campaign is initializing and after initializing the Dtr dynamic-text-replacement handler, and after the global text-replacement functions have been called.


Events Associated With A Campaign Showing [TOP]

om.Campaign.init [TOP]

Runs once when campaign is initialized.

In the following example, we’ll remove the campaign if a video is playing.


om.Campaign.normalize [TOP]

Runs just before any split test elements are normalized.


om.Campaign.canLoad [TOP]

Runs just after a successful check that a campaign is able to load. The campaign is not guaranteed to show.


om.DisplayRules.init [TOP]

Runs when the campaign wants to show, just before checking if the the display rules are passing.


om.Ruleset.init [TOP]

Runs when the campaign rulesets are being processed just before determining if the Ruleset passes.


om.Group.init [TOP]

Runs when the campaign rulesets are being processed just before determining if the Group in a Ruleset passes.


om.Rule.init [TOP]

Runs when the campaign rulesets are being processed just before determining if the Rule in a Group in a Ruleset passes.


om.WebFonts.init [TOP]

Runs when campaign is being initiated and handles initializing the webfonts object, just before any font-loading/pre-loading occurs.


om.Html.images [TOP]

Runs when campaign is being initiated and just before any image-loading/pre-loading occurs.


om.Campaign.startShow [TOP]

Happens before beginning the process of showing the campaign. Processes a couple more checks before showing, but has already passed the rules.


om.Campaign.canShow [TOP]

Runs just after a successful check that a campaign can show on the page (e.g. no other campaign is currently visible).


om.Campaign.show [TOP]

Runs before om.Campaign.load and before all campaign settings are initialized.

In this example, we’re going pause a video playing on the page if a certain campaign is about to show.


om.DisplayRules.actions [TOP]

Runs right before any display rules actions are run for rules that have successfully passed.


om.Html.show [TOP]

Runs right before the campaign form HTML is processed and appended.


om.Html.customVars [TOP]

Runs while the campaign form HTML is being processed and before the smart-tags are replaced.


om.Html.shortcodes [TOP]

Runs while the campaign form HTML is being processed and just before parsing any shortcodes for output on the page.


om.Html.append.before [TOP]

Runs while the campaign form HTML is being processed and just before appending it to the DOM.


om.Html.scripts [TOP]

Runs while the campaign form HTML is being processed and just before processing any scripts inside the HTML and adding them to the head of the page.


om.Html.inlineScripts [TOP]

Runs while the campaign form HTML is being processed, once the external scripts have finished loading, and just before we inject the inline scripts.


om.Html.append.after [TOP]

Runs when the campaign form HTML has been processed and appended to the DOM.

In this example, we’ll log a message when the main campaign container has been attached to the outer DOM.


om.Form.init [TOP]

Runs when the campaign form HTML has been appended to the DOM and just before initializing the campaign form attributes.


om.PoweredBy.init [TOP]

Runs when the campaign form HTML has been appended to the DOM and just before creating and appending the powered-by link.


om.Styles.init [TOP]

Runs when the campaign form HTML has been appended to the DOM and just before updating the campaign styles for display and before applying any monster effects.


om.Actions.init [TOP]

Runs when the campaign form HTML has been appended to the DOM and just before initializing the individual action events that are attached to elements in the campaign.


om.Action.init [TOP]

Runs when the campaign form HTML has been appended to the DOM and just before initializing an individual action event that is attached to elements in the campaign.


om.Countdown.init [TOP]

Runs when the campaign form HTML has been appended to the DOM and just before updating any countdown elements in the campaign.


om.Campaign.load [TOP]

Runs just before the campaign actually becomes visible.

In this example, we’ll write to the browser’s console a message to confirm the successful loading of our campaign.


om.Campaign.afterShow [TOP]

Runs just after a campaign becomes visible.


Events Associated With A Campaign Closing [TOP]

om.Campaign.startClose [TOP]

Runs at the start of the close function before we check for any conflicts with actually closing.


om.Campaign.close [TOP]

Runs at the end of the close function just before the close happens.

In this example, we’ll redirect users to a specific url when the campaign is closed.


om.Campaign.afterClose [TOP]

Runs just after the close function.

In this example we’ll play/resume a video on the page when the campaign closes.


om.Campaign.cleanup [TOP]

Runs before we set cookies, but after a close.


Events Associated With A Campaign Changing Views [TOP]

om.Campaign.changeView [TOP]

Runs right before any view is changed (e.g. Yesno to Optin).


om.Campaign.changeView.done [TOP]

Runs right after any view is changed.


Events Associated With A Campaign Optin Request [TOP]

om.Optin.init [TOP]

Runs at the start of a conversion attempting being triggered (e.g. click submit on a form before we check validation)


om.Optin.init.submit [TOP]

Runs at the start of a conversion attempting being triggered (e.g. click submit on a form before we check validation)

In this example, we’ll add a custom redirect url (https://optinmonster.com/) if the subscriber uses a non-business email address such as yahoo, gmail, hotmail, etc.


om.Optin.error [TOP]

Runs any time there is an error in the Optin conversion, but not during validation (e.g. MailChimp responds with test email not allowed).

In this example, we’ll redirect users to a specific url if there’s an error.


om.Optin.success [TOP]

Runs after a successful conversion.

In this example we’ll close the campaign after a successful conversion. This could be useful where the redirect url results in a direct file download and the campaign remains visible in the browser.


Analytics Events [TOP]

om.Analytics.track [TOP]

Runs any time we are tracking an impression or conversion.

In this example we’ll log a message to the console to let us know our campaign has successfully tracked an impression or conversion.

And in this example, we’ll use Google Tag Manager to track a specific event in our Google Analytics account. If you’re unfamiliar with Google Tag Manager, consider reading The Definitive Guide to Triggering Custom Google Analytics Events Using Google Tag Manager and in Step 4 we’ll be triggering the tag event when om.Analytics.track fires and the event type is a conversion.


om.Analytics.impression [TOP]

Runs any time we are attempting to track an impression. To actually know when an impression is tracked, you will need to use the om.Analytics.track event.


om.Analytics.conversion [TOP]

Runs any time we are attempting to track a conversion. To actually know when a conversion is tracked, you will need to use the om.Analytics.track event.


Element Action Events [TOP]

om.Action.redirect [TOP]

Runs before a redirect action happens.

In this example we’ll log a message in the browser’s console when the page is about to redirect to the Success URL.


om.Action.view [TOP]

Runs before a view change happens based on an action.


om.Action.close [TOP]

Runs before a close is supposed to happen based on an action.

In this example we’ll close the campaign on success, then begin a direct file download.


om.Action.window [TOP]

Runs before a new window is opened based on an action.


om.Action.refresh [TOP]

Runs before a campaign closes and the page refreshes based on an action.


Miscellaneous Events [TOP]

om.Campaign.reset [TOP]

Runs when a manual campaign reset has been called. The API will never call reset itself.


om.Styles.positionPopup [TOP]

Runs any time the campaign is positioned in the window. Runs only for Fullscreen and Popup campaigns.

In this example, we’ll make our Popup campaign draggable with the Dragon jQuery plugin once it’s been positioned on the page. Be sure to enqueue the required files, including jQuery. We recommend you review the readme file for the plugin.