All features

JavaScript event

Show your popup the moment your site fires an event you name: a login, a filter change, a checkout step.

What it is

JavaScript event, in plain words.

The standard triggers watch what a visitor does on the page: how long they stay, how far they scroll, whether they're about to leave. But some moments only your own site knows about. A customer logs in, applies a filter, adds a gift card, or reaches a step in a custom checkout.

The JavaScript event trigger covers those moments. You give the event a name in the campaign's settings. When your site fires a DOM event with that exact name, on the document or on the html element, the popup appears.

It takes one line of code on your side, usually added by your developer: document.dispatchEvent(new Event('user_login', { bubbles: true })). From then on, the campaign reacts to that moment like it would to any other trigger.

Use it when none of the other five triggers fits. If the moment can be described as a delay, scrolling, exit intent, a click or inactivity, one of those is simpler and needs no code.

When to use it

Where it pays off.

Right after a customer logs in.

Fire user_login when someone signs in, and greet them with a members-only offer or a nudge to finish their profile.

When a shopper narrows down the catalog.

Fire an event when a filter is applied, and offer help choosing, or a discount on the category they're looking at.

At a step in your own checkout.

A one-page checkout doesn't load new pages, so URL rules can't see its steps. Fire an event at the step that matters, like choosing delivery.

After an action in your own widget.

A size finder, a configurator or a quiz you built yourself can fire an event when it finishes, and the popup takes it from there.

Key benefits

Why it earns its place.

01

Any moment your site knows about.

If your code can tell something happened, your popup can react to it. You're not limited to what the standard triggers can see.

02

Several events, one campaign.

Add up to 20 event names. Any one of them opens the popup, so one campaign can cover a login and a sign-up alike.

03

Devices per event.

Each event name has its own Desktop / Mobile switch, so one event can open the popup everywhere and another only on desktop.

How it works

Set it up in three steps.

  1. 1
    Step 1

    Name the event

    On the campaign's Settings tab, under When will the popup show up, click Add trigger and pick On a JavaScript event. Enter an Event name, for example user_login, and choose the devices.

  2. 2
    Step 2

    Fire it from your code

    Add one line where the moment happens: document.dispatchEvent(new Event('user_login', { bubbles: true })). The name has to match exactly.

  3. 3
    Step 3

    Save and test

    Click Save, then Save changes. Then do the action on your site and check that the popup appears.

Settings & limits

Good to know.

Your site has to fire the event.

OptiMonk listens for it, but the event comes from your own code. Without that line, the trigger never fires.

Names without spaces.

An event name can't contain spaces. You can add up to 20 names to one trigger.

The assistant won't guess a name.

Ask for this trigger in chat and the assistant sets it up, but only with an event name you give it. It never makes one up.

One trigger among the others.

It combines with the campaign's other triggers with OR. Frequency limits and targeting rules still apply on top.

Questions, answered.

Step-by-step setup lives in the Help Center guide.

OptiMonk monk meditating in lotus pose

Try JavaScript event
on your own store.

Free to start. No credit card.