Home

Awesome

Boost User Engagement with Exit Intent Detection.

A composable to show your modal when a user is about to leave the page or another threshold reached.

Demo

The very first version of this package created in favor of this old guide. Here is an updated article regarding the latest version.

Usage

Import the composable and show your content according to the value of isShowing.

When the exit intent is triggered, a key-value pair (with the current timestamp) is stored in localStorage. The timestamp will be re-evaluated according to the given options the next time the user intends to exit your app.

Add the package

npm i vue-exit-intent
If you are using Vue versions earlier than 2.7, you need to install the @vue/composition-api plugin because Composition API is not supported natively.

Use the package

<sript setup lang="ts">
import { useVueExitIntent } from 'vue-exit-intent'

const { isShowing, close } = useVueExitIntent();
</script>
<template>
  <dialog :open="isShowing">
    <p>Exit intent detected!</p>
    <form method="dialog">
      <button value="ok" @click="close()">OK</button>
    </form>
  </dialog>
</template>

Available helpers & Options

If you use all available helpers & some options your code will be like this:

const options = {
  repeatAfterDays: 1,
  scrollPercentageToTrigger: 50,
  handleScrollBars: true,
  LSItemKey: 'exit-intent-local-storage-key',
  setupBeforeMount: true
};

const {
  isShowing,
  isAllowedToGetTriggered,
  isUnsubscribed,
  close,
  resetState,
  unsubscribe
} = useVueExitIntent(options);

Helpers

isShowing: a reactive boolean ref that tracks whether the exit intent popup is currently visible.
isAllowedToGetTriggered: a reactive boolean ref that tracks whether the exit intent popup is allowed to trigger.
isUnsubscribed: a reactive boolean ref that tracks whether the user has unsubscribed from the exit intent popup.
close: a function that closes the exit intent popup and resets any related states (e.g. the isShowing ref).
resetState: a function that resets all state related to the exit intent popup (e.g. isShowing, isAllowedToGetTriggered, isUnsubscribed).
unsubscribe: a function that unsubscribes the user from the exit intent popup.

Options

KeyDefault ValueTypeRequired
repeatAfterDays7numberfalse
scrollPercentageToTrigger0numberfalse
delaySecondsAndTrigger0numberfalse
triggerOnExitIntenttruebooleanfalse
touchDeviceSensitivity15numberfalse
scrollDebounceMillis300numberfalse
triggerOnPageLoadfalsebooleanfalse
handleScrollBarsfalsebooleanfalse
LSItemKey'vue-exit-intent'stringfalse
setupBeforeMountfalsebooleanfalse
inactiveSeconds0numberfalse

Options Description

Contribute

Feel free to contribute, message me for your ideas.

Instructions for Contributors

Project Setup

npm install

Compile and Hot-Reload for Development

npm run dev

Compile and Minify for Production

npm run build

Lint with ESLint

npm run lint

Recommended IDE Setup

VSCode + Volar (and disable Vetur) + TypeScript Vue Plugin (Volar).

Customize configuration

See Vite Configuration Reference.

License

The MIT License (MIT)

Copyright © 2022 nickap

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.