Next Commerce
UtilitiesExit Intent

Get Started

The fastest path is an image popup that applies a coupon when clicked.


Minimal Setup (Image)

<script>
  window.addEventListener('next:initialized', () => {
    next.exitIntent({
      image: 'https://example.com/exit-popup.webp',
      action: async () => {
        const result = await next.applyCoupon('SAVE10');
        if (result.success) console.log('Coupon applied');
      },
    });
  });
</script>

That is the complete setup. The popup fires the first time the visitor moves their mouse to leave the page. Clicking the image runs your action and closes the popup. Clicking the overlay also closes the popup, without running the action.


Verify It Is Working

After the page loads on desktop:

  1. Move your mouse out the top of the viewport. The popup should appear.
  2. Click the image. Your action callback runs.
  3. Refresh the page and try again. The popup should not reappear — it remembers the dismissal in sessionStorage.

Console output to look for:

  • [ExitIntentEnhancer] Simple exit intent setup complete
  • [ExitIntentEnhancer] Exit intent triggered

If nothing happens:

  • The enhancer is disabled on mobile by default. Test on a desktop viewport (>= 768px) or pass disableOnMobile: false.
  • Check sessionStorage for next-exit-intent-dismissed. Clear it to re-enable the popup for testing.

Reset for Testing

The dismissal is stored in sessionStorage.next-exit-intent-dismissed. To re-enable the popup during development, clear it from the console:

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

Or call the disable method to tear down the active popup completely:

next.disableExitIntent();

disableExitIntent() removes event listeners and hides any visible popup. You will need to call next.exitIntent({...}) again to reactivate it.


Next Steps

On this page