Skip to content

A tiny library to detect user intent (exit intent) and trigger a callback. It's built with pure JavaScript and supports multiple triggers. Made for better user engagements.

License

Notifications You must be signed in to change notification settings

Teknasyon-Teknoloji/user-intent

Repository files navigation

User Intent (Exit Intent) 🚀

Detect user intent and trigger a callback.

Usage 👨‍💻

Idleness

const options = {
    mode: 'idle',
    events: ['mousedown', 'mousemove', 'keypress', 'scroll', 'touchstart'],
    delay: 10000,
    multiple: false,
};

const cb = (mode, opts) => {
    console.log(`Callback -> mode is "${mode}" with options of "${JSON.stringify(opts)}"`);
};

new UserIntent(cb, options);

Scroll

const options = {
    mode: 'scroll',
    percentDown: 50,
    percentUp: 0,
    offsetTop: 0,
    offsetBottom: 0,
};

const cb = (mode, opts) => {
    console.log(`Callback -> mode is "${mode}" with options of "${JSON.stringify(opts)}"`);
};

new UserIntent(cb, options);

Target Element

const options = {
    mode: 'target',
    target: '',
    offsetTop: 0,
    offsetBottom: 0,
    multiple: false,
};

const cb = (mode, opts) => {
    console.log(`Callback -> mode is "${mode}" with options of "${JSON.stringify(opts)}"`);
};

new UserIntent(cb, options);

Window Focus

const options = {
    mode: 'focus',
    multiple: false,
};

const cb = (mode, opts) => {
    console.log(`Callback -> mode is "${mode}" with options of "${JSON.stringify(opts)}"`);
};

new UserIntent(cb, options);

Window Out

const options = {
    mode: 'out',
    multiple: false,
};

const cb = (mode, opts) => {
    console.log(`Callback -> mode is "${mode}" with options of "${JSON.stringify(opts)}"`);
};

new UserIntent(cb, options);

How to launch the project 🏁

Install Node.js and then open the Terminal/CMD and navigate to the project's folder. Run the following command:

npm install

Development evnironment

npm start

Production build

npm run build

Builds the app for production to the build folder.\

Stay safe 😷

About

A tiny library to detect user intent (exit intent) and trigger a callback. It's built with pure JavaScript and supports multiple triggers. Made for better user engagements.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published