Next Commerce
UtilitiesExit IntentReference

API

Methods

next.exitIntent(options)

Initialize and activate the exit intent enhancer. Lazy-loads the enhancer on first call and replaces the active config on subsequent calls.

await next.exitIntent({
  image: 'https://example.com/popup.webp',
  action: () => next.applyCoupon('SAVE10'),
});

Returns a Promise<void>. Safe to call inside or after next:initialized.

You must pass either image or template — not neither, not both.

next.disableExitIntent()

Stop listening for exit intent triggers and tear down any active popup. Calling next.exitIntent({...}) again reactivates it.

next.disableExitIntent();

Configuration Options

OptionTypeDefaultDescription
imagestringURL of an image to display. Required if template is not set
templatestringName of a <template data-template="..."> element. Required if image is not set
action() => void | Promise<void>Callback. In image mode, runs on image click. In template mode, runs only when a data-exit-intent-action="custom" button is clicked
actionButtonTextstring''If set in image mode, renders a CTA button with this text instead of making the image clickable
imageClickablebooleantrueIn image mode, controls whether the image itself runs the action on click
disableOnMobilebooleantrueDisables the enhancer on mobile devices
mobileScrollTriggerbooleanfalseWhen mobile is enabled, triggers the popup at 50% scroll instead of mouse-leave
maxTriggersnumber1Maximum number of times the popup can fire in a session
overlayClosablebooleantrueAllow clicking the overlay to dismiss
showCloseButtonbooleanfalseRender an X button on the modal
useSessionStoragebooleantruePersist trigger count and dismissal in sessionStorage
sessionStorageKeystring'next-exit-intent-dismissed'The sessionStorage key used for persistence

Mobile is disabled by default. To make exit intent work on mobile, you need both disableOnMobile: false and mobileScrollTrigger: true. Setting only one of them does nothing.


Trigger Logic

Desktop

  • Listens for mouseout events on document.documentElement
  • Fires when clientY <= 10 and relatedTarget is null or <html> (cross-browser way to detect the cursor leaving the viewport top)
  • Built-in 30-second cooldown between triggers

Mobile (when enabled)

  • Listens for scroll events on window
  • Fires when scroll percentage >= 50% of document.body.scrollHeight - window.innerHeight
  • Built-in 30-second cooldown between triggers

Mobile detection

A device is considered mobile when both are true:

  • 'ontouchstart' in window || navigator.maxTouchPoints > 0 (touch-capable)
  • AND (window.innerWidth < 768 OR the user agent matches /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i)

Session Persistence

When useSessionStorage is true (the default), the enhancer stores:

{
  "triggerCount": 1,
  "lastTriggerTime": 1712345678901
}

at sessionStorage[sessionStorageKey]. Once triggerCount >= maxTriggers, no further triggers fire until the session ends or you clear the key manually.

To reset for testing:

sessionStorage.removeItem('next-exit-intent-dismissed');

On this page