{"_id":"exit-intent-js","_rev":"4-78e4afb65db9ee23aa64ef4f7881dad1","name":"exit-intent-js","dist-tags":{"latest":"1.2.0"},"versions":{"1.0.0":{"name":"exit-intent-js","version":"1.0.0","keywords":["exit-intent","exit intent","popup","user engagement","javascript","vanilla js"],"author":{"name":"James Bathgate","email":"julesbravo@gmail.com"},"license":"MIT","_id":"exit-intent-js@1.0.0","maintainers":[{"name":"julesbravo","email":"julesbravo@gmail.com"}],"homepage":"https://github.com/julesbravo/exit-intent-js#readme","bugs":{"url":"https://github.com/julesbravo/exit-intent-js/issues"},"dist":{"shasum":"28a7cb23c5b88d475cb6f184abf7b043c3d62ecf","tarball":"https://registry.npmjs.org/exit-intent-js/-/exit-intent-js-1.0.0.tgz","fileCount":5,"integrity":"sha512-umcZNwP86Jv6z/NwGpyPRbuH70YV4Gv4XFXNgZzXUFsr+A3HPEFoW+41grxBMkuoT3jvtsJh/i8y/6P3FRvU6Q==","signatures":[{"sig":"MEUCIQCEImjiTzFr63MPVzpAyPh4okpeBjHMaxGqdhYYUBm7MgIgFmG8ECntyPvi1xNWuO+Vd+trNhbhXAAYpDfV9bpBIAA=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":11011},"main":"src/exit-intent.js","gitHead":"5b22f4f2a65d4ffd2c52fce65a4f18c956aea31b","scripts":{"test":"cypress run","cy-open":"cypress open","cy-test":"cypress run"},"_npmUser":{"name":"julesbravo","email":"julesbravo@gmail.com"},"repository":{"url":"git+https://github.com/julesbravo/exit-intent-js.git","type":"git"},"_npmVersion":"10.2.3","description":"Lightweight, dependency-free JavaScript utility for detecting exit-intent. Fires a single custom event when the user looks like they're about to leave – based on time-on-page, idle time, mouse-leave, tab visibility & window blur. Perfect for pop-ups, surv","directories":{},"_nodeVersion":"18.19.0","_hasShrinkwrap":false,"devDependencies":{"cypress":"^14.3.2"},"_npmOperationalInternal":{"tmp":"tmp/exit-intent-js_1.0.0_1747924110710_0.18645948973905258","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"exit-intent-js","version":"1.1.0","keywords":["exit-intent","exit intent","popup","user engagement","javascript","vanilla js"],"author":{"name":"James Bathgate","email":"julesbravo@gmail.com"},"license":"MIT","_id":"exit-intent-js@1.1.0","maintainers":[{"name":"julesbravo","email":"julesbravo@gmail.com"}],"homepage":"https://github.com/julesbravo/exit-intent-js#readme","bugs":{"url":"https://github.com/julesbravo/exit-intent-js/issues"},"dist":{"shasum":"c4de36047b2989580e86ab399bfc1797348c1b8d","tarball":"https://registry.npmjs.org/exit-intent-js/-/exit-intent-js-1.1.0.tgz","fileCount":5,"integrity":"sha512-TYWtmpijEtwooSSGkouuYP/uP8IcDdKdKqYOnhrsT7YSD7NMhvWmUeXgxz43YtO6vlWpPgt6o16NpklXTFy1wQ==","signatures":[{"sig":"MEQCIAsZMzsLNxnwDbUJQciWi+EBQb6Z7ovYWOF5cgGpDP0CAiB9iH0En1YdqGpzRTH9BMtNw4EnxNff4fw/zf4EL06LqQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":12904},"main":"src/exit-intent.js","gitHead":"6b49af7f5c8f64f83ca58f484ae767cbe19efe4b","scripts":{"test":"cypress run","cy-open":"cypress open","cy-test":"cypress run"},"_npmUser":{"name":"julesbravo","email":"julesbravo@gmail.com"},"repository":{"url":"git+https://github.com/julesbravo/exit-intent-js.git","type":"git"},"_npmVersion":"10.2.3","description":"Lightweight, dependency-free JavaScript utility for detecting exit-intent. Fires a single custom event when the user looks like they're about to leave – based on time-on-page, idle time, mouse-leave, tab visibility & window blur. Perfect for pop-ups, surv","directories":{},"_nodeVersion":"18.19.0","_hasShrinkwrap":false,"devDependencies":{"cypress":"^14.3.2"},"_npmOperationalInternal":{"tmp":"tmp/exit-intent-js_1.1.0_1750102437641_0.3798601305085736","host":"s3://npm-registry-packages-npm-production"}},"1.1.1":{"name":"exit-intent-js","version":"1.1.1","keywords":["exit-intent","exit intent","popup","user engagement","javascript","vanilla js"],"author":{"name":"James Bathgate","email":"julesbravo@gmail.com"},"license":"MIT","_id":"exit-intent-js@1.1.1","maintainers":[{"name":"julesbravo","email":"julesbravo@gmail.com"}],"homepage":"https://github.com/julesbravo/exit-intent-js#readme","bugs":{"url":"https://github.com/julesbravo/exit-intent-js/issues"},"dist":{"shasum":"6807a9a511929ee9ba49cbe82d0c1a214c14368b","tarball":"https://registry.npmjs.org/exit-intent-js/-/exit-intent-js-1.1.1.tgz","fileCount":5,"integrity":"sha512-IDheo840UuOERAKNe8+Q778EmftiTZmo7SqA3KakI/eJ+gI90I+HUmlQgFSVGmYaZ0j4vH+ud8xcQEjK/MdbkA==","signatures":[{"sig":"MEYCIQDCTLx9Bak3pdHoqQkohgiwpkBe80QFd56cLxkVKb+5ZgIhANI8VrhQzRXczeIiK9SNFfl5m9umba61poLgh9ToR6N+","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":13907},"main":"src/exit-intent.js","gitHead":"17b58fcb5be47516ff3ffad6f21c8aac6e1d780d","scripts":{"test":"cypress run","cy-open":"cypress open","cy-test":"cypress run"},"_npmUser":{"name":"julesbravo","email":"julesbravo@gmail.com"},"repository":{"url":"git+https://github.com/julesbravo/exit-intent-js.git","type":"git"},"_npmVersion":"10.2.3","description":"Lightweight, dependency-free JavaScript utility for detecting exit-intent. Fires a single custom event when the user looks like they're about to leave – based on time-on-page, idle time, mouse-leave, tab visibility & window blur. Perfect for pop-ups, surv","directories":{},"_nodeVersion":"18.19.0","_hasShrinkwrap":false,"devDependencies":{"cypress":"^14.3.2"},"_npmOperationalInternal":{"tmp":"tmp/exit-intent-js_1.1.1_1750103085811_0.1827670288589871","host":"s3://npm-registry-packages-npm-production"}},"1.2.0":{"name":"exit-intent-js","version":"1.2.0","description":"Lightweight, dependency-free JavaScript utility for detecting exit-intent. Fires a single custom event when the user looks like they're about to leave – based on time-on-page, idle time, mouse-leave, tab visibility & window blur. Perfect for pop-ups, surv","main":"src/exit-intent.js","scripts":{"test":"cypress run","cy-test":"cypress run","cy-open":"cypress open"},"keywords":["exit-intent","exit intent","popup","user engagement","javascript","vanilla js"],"author":{"name":"James Bathgate","email":"julesbravo@gmail.com"},"license":"MIT","devDependencies":{"cypress":"^14.3.2"},"repository":{"type":"git","url":"git+https://github.com/julesbravo/exit-intent-js.git"},"bugs":{"url":"https://github.com/julesbravo/exit-intent-js/issues"},"homepage":"https://github.com/julesbravo/exit-intent-js#readme","_id":"exit-intent-js@1.2.0","gitHead":"ac4d242b13c144feb6e699e9cb3453e971a447bb","_nodeVersion":"18.19.0","_npmVersion":"10.2.3","dist":{"integrity":"sha512-iWbt5oGtfHdGCnOC7WDrHp0phdfNlQM/nqh8Cb1ITq9eXjWB76avoMvPi+TKtC/yMPMmUlRf7xP0g21onUO4jA==","shasum":"faadce7e2256c959e0d3cc47666a491c4e2c9456","tarball":"https://registry.npmjs.org/exit-intent-js/-/exit-intent-js-1.2.0.tgz","fileCount":5,"unpackedSize":19252,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIAlmBoQV3ug7GVEfX+s5MwDiSloIVL2WtPL8U2O7jIDXAiEAh2w1WGJB+4uRaH5K+C2K1r+yBRrKvWzMxsCO7etQJrk="}]},"_npmUser":{"name":"julesbravo","email":"julesbravo@gmail.com","actor":{"name":"julesbravo","email":"julesbravo@gmail.com","type":"user"}},"directories":{},"maintainers":[{"name":"julesbravo","email":"julesbravo@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/exit-intent-js_1.2.0_1751988002844_0.13270910119136925"},"_hasShrinkwrap":false}},"time":{"created":"2025-05-22T14:28:30.635Z","modified":"2025-07-08T15:20:03.207Z","1.0.0":"2025-05-22T14:28:30.895Z","1.1.0":"2025-06-16T19:33:57.817Z","1.1.1":"2025-06-16T19:44:45.994Z","1.2.0":"2025-07-08T15:20:03.040Z"},"bugs":{"url":"https://github.com/julesbravo/exit-intent-js/issues"},"author":{"name":"James Bathgate","email":"julesbravo@gmail.com"},"license":"MIT","homepage":"https://github.com/julesbravo/exit-intent-js#readme","keywords":["exit-intent","exit intent","popup","user engagement","javascript","vanilla js"],"repository":{"type":"git","url":"git+https://github.com/julesbravo/exit-intent-js.git"},"description":"Lightweight, dependency-free JavaScript utility for detecting exit-intent. Fires a single custom event when the user looks like they're about to leave – based on time-on-page, idle time, mouse-leave, tab visibility & window blur. Perfect for pop-ups, surv","maintainers":[{"name":"julesbravo","email":"julesbravo@gmail.com"}],"readme":"# Exit Intent Detection Library\n[![npm](https://img.shields.io/npm/v/exit-intent-js)](https://www.npmjs.com/package/exit-intent-js) [![CI](https://github.com/julesbravo/exit-intent-js/actions/workflows/ci.yml/badge.svg)](https://github.com/julesbravo/exit-intent-js/actions/workflows/ci.yml) [![License](https://img.shields.io/github/license/julesbravo/exit-intent-js)](LICENSE)\n\nA lightweight, vanilla JavaScript library for detecting exit intent on web pages. Useful for showing popups, surveys, or capturing feedback before users leave your site.\n\n## Features\n- Detects exit intent via multiple signals:\n  - Time on page\n  - User idle time\n  - Mouse leaves window\n  - Tab/document visibility change\n  - Window loses focus (blur)\n  - Pages Viewed\n  - Fast upward scrolling\n- Customizable options\n- Simple API\n- No dependencies\n\n## Installation\n\nCopy `src/exit-intent.js` into your project, or install via npm (if published):\n\n```sh\nnpm install exit-intent-js\n```\n\n## Usage\n\n```js\nimport observeExitIntent from './src/exit-intent';\n\nconst { destroy } = observeExitIntent({\n  eventName: 'my-exit-event',\n  timeOnPage: 10000,\n  debug: true\n});\n\nwindow.addEventListener('my-exit-event', e => {\n  console.log('Exit intent detected:', e.detail);\n});\n\n// To manually clean up listeners and timers:\n// destroy();\n```\n\n## Options\n\n| Option            | Type     | Default      | Description                                                                 |\n|-------------------|----------|--------------|-----------------------------------------------------------------------------|\n| `timeOnPage`      | number   | `15000`      | Time (ms) spent on page before triggering exit intent. `0` disables.        |\n| `idleTime`        | number   | `8000`       | Time (ms) idle (no interaction) before triggering. `0` disables.            |\n| `mouseLeaveDelay` | number   | `1000`       | Delay (ms) after mouse leaves window before triggering. `0` disables.       |\n| `tabChange`       | boolean  | `true`       | Trigger when tab/document becomes hidden.                                    |\n| `windowBlur`      | boolean  | `true`       | Trigger when window loses focus (user switches tabs/apps or minimizes).      |\n| `eventName`       | string   | `'exit-intent'` | Name of the custom event dispatched on window.                          |\n| `debug`           | boolean  | `false`      | Enable debug logging to console.                                            |\n| `pageViewsToTrigger` | number | `0` | Fire the exit-intent event immediately once the stored page-view counter reaches this threshold. `0` disables the feature. |\n| `scrollUpThreshold` | number\\|object | `{mobile: 200, desktop: 400}` | Minimum pixels scrolled up to trigger exit intent. Can be a number (legacy) or object with `mobile` and `desktop` properties for responsive thresholds. |\n| `mobileBreakpoint` | number | `768` | Screen width threshold (px) for mobile detection. Used with responsive `scrollUpThreshold`. |\n| `scrollUpInterval` | number | `100` | Interval (ms) to check scroll position for upward movement. |\n\nBy default the library stores a persistent page-view counter in `localStorage` under the key `exit-intent-page-views` and automatically increments that value every time the script is evaluated (i.e. on a full page load).  \nIf you have a single-page-app (SPA) and want to increment the counter on client-side route changes, call:\n\n```js\nobserveExitIntent.incrementPageViews(); // bump by 1 (or pass a custom amount)\n```\n\n## Responsive Scroll Thresholds\n\nThe `scrollUpThreshold` option supports responsive thresholds for different device types:\n\n### Object Format (Recommended)\n```js\nobserveExitIntent({\n  scrollUpThreshold: {\n    mobile: 200,   // Lower threshold for mobile devices (≤ 768px)\n    desktop: 400   // Higher threshold for desktop devices (> 768px)\n  },\n  mobileBreakpoint: 768 // Screen width threshold for mobile detection\n});\n```\n\n### Legacy Number Format (Still Supported)\n```js\nobserveExitIntent({\n  scrollUpThreshold: 300 // Same threshold for all devices\n});\n```\n\n### Benefits of Responsive Thresholds\n- **Mobile devices**: Lower threshold (200px) makes it easier to trigger on touch devices where scrolling patterns differ\n- **Desktop devices**: Higher threshold (400px) reduces false positives from mouse wheel scrolling\n- **Automatic detection**: The library automatically detects device type based on screen width\n- **Backward compatibility**: Existing code using number values continues to work\n\n## Exit Intent Reasons\n\nThe custom event's `detail` property will be one of:\n- `'timeOnPage'`    — Time on page exceeded\n- `'idleTime'`      — User idle for too long\n- `'mouseLeave'`    — Mouse left window\n- `'tabChange'`     — Tab/document became hidden\n- `'windowBlur'`    — Window lost focus\n- `'scrollUp'`      — User scrolled up quickly\n\n## Examples\n\n### 1. Basic usage (vanilla JS)\n\n```js\nobserveExitIntent({\n  timeOnPage: 5000,\n  idleTime: 3000,\n  mouseLeaveDelay: 500,\n  tabChange: true,\n  windowBlur: true,\n  scrollUpThreshold: {\n    mobile: 200,   // 200px threshold for mobile devices\n    desktop: 400   // 400px threshold for desktop devices\n  },\n  mobileBreakpoint: 768,\n  scrollUpInterval: 50,\n  eventName: 'exit-intent',\n  debug: true\n});\n\nwindow.addEventListener('exit-intent', e => {\n  alert('Exit intent detected! Reason: ' + e.detail);\n});\n```\n\n### 2. Triggering a Postscript Popup on exit-intent\n\nIf you use [Postscript](https://postscript.io/) for SMS pop-ups, you can open a popup only when exit intent is detected. A full working page lives in [`examples/postscript.html`](examples/postscript.html). \n---\n\n## Cleanup\n\nThe function returns an object with a `destroy` method to remove all listeners and timers:\n\n```js\nconst { destroy } = observeExitIntent();\n// ...\ndestroy();\n```\n\n## License\nMIT ","readmeFilename":"README.md"}