Giter Club home page Giter Club logo

ouibounce's Introduction

Ouibounce

Originally created by Carl Sednaoui from MailCharts. Maintained and improved by generous contributors.

tests twitter

Ouibounce: A small library enabling you to display a modal before a user leaves your website.

Quick note: Let me know if you end up using Ouibounce. I'd love to hear about your project / see Ouibounce in the wild :)

The philosophy behind this project

This library helps you increase landing page conversion rates. From my experience, you can expect a lift of 7% to 15% depending on your audience, traffic type (paid or unpaid) and copy.

Talking about copy... please use Ouibounce to provide value to your visitors. With tools like these it's very easy to create something spammy-looking.

Not sure what I mean by provide value? Here are a few ideas to get your creative juices flowing:

Demo / Examples

Modal inspiration

I've designed a few modals just for you. Feel free to use these as inspiration.

fancy with content fancy no header simple simple with book simple with feedback

Installation

You have a few options to choose from:

  • Download the minified or unminified script and include it on your page
  • Get Ouibounce from cdnjs.com
  • Use Bower: curl http://bower.herokuapp.com/packages/ouibounce
  • Use NPM: npm install ouibounce

Note: Ouibounce is wrapped by a umd wrapper, so if you are using requirejs/amd or commonjs/browserify, it will still work fine.

Usage

  1. Create a hidden modal
  2. Select the modal with vanilla JavaScript (or jQuery) and call ouibounce
  3. Optional: Save the function's return value to use the public API, allowing you to fire or disable Ouibounce on demand

Example:

ouibounce(document.getElementById('ouibounce-modal'));

Example with jQuery:

ouibounce($('#ouibounce-modal')[0]);

Example using the public api:

var modal = ouibounce(document.getElementById('ouibounce-modal'));
modal.fire()

Options

Ouibounce offers a few options, such as:

Sensitivity

Ouibounce fires when the mouse cursor moves close to (or passes) the top of the viewport. You can define how far the mouse has to be before Ouibounce fires. The higher value, the more sensitive, and the more quickly the event will fire. Defaults to 20.

Example:

ouibounce(document.getElementById('ouibounce-modal'), { sensitivity: 40 });
Aggressive mode

By default, Ouibounce will only fire once for each visitor. When Ouibounce fires, a cookie is created to ensure a non obtrusive experience.

There are cases, however, when you may want to be more aggressive (as in, you want the modal to be elegible to fire anytime the page is loaded/ reloaded). An example use-case might be on your paid landing pages. If you enable aggressive, the modal will fire any time the page is reloaded, for the same user.

Example:

ouibounce(document.getElementById('ouibounce-modal'), { aggressive: true });
Set a min time before Ouibounce fires

By default, Ouibounce won't fire in the first second to prevent false positives, as it's unlikely the user will be able to exit the page within less than a second. If you want to change the amount of time that firing is surpressed for, you can pass in a number of milliseconds to timer.

Example:

ouibounce(document.getElementById('ouibounce-modal'), { timer: 0 });
Delay

By default, Ouibounce will show the modal immediately. You could instead configure it to wait x milliseconds before showing the modal. If the user's mouse re-enters the body before delay ms have passed, the modal will not appear. This can be used to provide a "grace period" for visitors instead of immediately presenting the modal window.

Example:

// Wait 100 ms
ouibounce(document.getElementById('ouibounce-modal'), { delay: 100 });
Callback

You can add a callback, which is a function that will run once Ouibounce has been triggered, by using the callback option.

Example:

ouibounce(document.getElementById('ouibounce-modal'), { callback: function() { console.log('Ouibounce fired!'); } });
Cookie expiration

Ouibounce sets a cookie by default to prevent the modal from appearing more than once per user. You can add a cookie expiration (in days) using cookieExpire to adjust the time period before the modal will appear again for a user. By default, the cookie will expire at the end of the session, which for most browsers is when the browser is closed entirely.

Example:

ouibounce(document.getElementById('ouibounce-modal'), { cookieExpire: 10 });
Cookie domain

Ouibounce sets a cookie by default to prevent the modal from appearing more than once per user. You can add a cookie domain using cookieDomain to specify the domain under which the cookie should work. By default, no extra domain information will be added. If you need a cookie to work also in your subdomain (like blog.example.com and example.com), then set a cookieDomain such as .example.com (notice the dot in front).

Example:

ouibounce(document.getElementById('ouibounce-modal'), { cookieDomain:
'.example.com' });
Cookie name

You can specify cookie name passing cookieName: 'customCookieName'.

Example:

ouibounce(document.getElementById('ouibounce-modal'), { cookieName: 'customCookieName' });
Sitewide cookie

You can drop sitewide cookies by using passing sitewide: true.

Example:

ouibounce(document.getElementById('ouibounce-modal'), { sitewide: true });
Chaining options

The options are just javascript objects, you can therefore combine multiple options.

Example:

ouibounce(document.getElementById('ouibounce-modal'), {
  aggressive: true,
  sitewide: true,
  cookieDomain: '.example.com',
  timer: 0,
  callback: function() { console.log('ouibounce fired!'); }
});

Ouibounce API

If you save the object returned by the ouibounce function, you get access to a small public API. Use this API to fire or disable Ouibounce on demand.

Example:

var modal = ouibounce(document.getElementById('ouibounce-modal'));
modal.fire(); // fire the ouibounce event
modal.disable() // disable ouibounce, it will not fire on page exit
modal.disable({ cookieExpire: 50, sitewide: true }) // disable ouibounce sitewide for 50 days. 
Disable options

The disable function accepts a few options:

Using Ouibounce with other libraries

If you want to use this library with other plugins — such as Vex — you can call ouibounce with false. See #30 for discussion.

var _ouibounce = ouibounce(false, {
  callback: function() { console.log('ouibounce fired!'); }
});
Twitter Bootstrap

If you're trying to use Ouibounce with Twitter Bootstrap and are simply copying the example code I've included in the demo, you might run into some problems. See #66 to fix this.

Legacy JS engines

If you'd like Ouibounce to work in legacy JS engines (IE8 and below, for example), you'll need to add a shim such as es5-shim.

WordPress

Tomaž wrote a great tutorial on how to build your own WordPress opt-in form.

Kevin Weber wrote wBounce, a WordPress plugin. I personally have not tested it, but have heard it works really well. Check it out.

Miscellaneous

Analytics

ouibounce's People

Contributors

bergerjac avatar carlsednaoui avatar colinodell avatar dz0ny avatar filipekiss avatar jdeniau avatar kevinweber avatar mcg88 avatar nilsine avatar rendez avatar schonfeld avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ouibounce's Issues

Twitter Bootstap Issue

Hi,

We prepare a page and use ouibounce. We make every detail just same as examples. Modal open but we can't see. (We test it, when we inactive twitter bootstrap it work but when we use twitter bootstrap it won't work)

How can we fix that?

Consider detecting window focus

As per #25.

When a user clicks a link to open in a background tab and then uses the mouse to view said tab ouibounce is likely to fire.

An option to consider would be to use window.onblur and/ or window.onfocus. More info here.

Move cookie check to initialization for efficiency?

If you checkCookieValue (+ aggressive) before attaching listeners, you'll prevent attaching what are effectively unnecessary cycles of calculation.

This could be a problem if user leaves a page open for a while and the cookie expires in the interim. If you consider that scenario significant, could add an optional flag lazyCheck and use in line 33 (and line 40) like:

if( ...other conditions... || (!aggressive && (lazyCheck || checkCookieValue(...))) ) // stop

Create a few modal templates

Make it as easy as possible for people to use this library. Creating pre-generated / designed templates would help.

close modal with click anywhere outside the modal?

i've used OUI on my site, pjrvs.com, for a while and i love it. only complaint i get from folks is trying to click anywhere off the modal and it not closing. that'd be the only thing i wish it did. cheers!

Modal appears when entering page rather than leaving

Chrome 35.0.1916.114 m

  1. Open demo page in new tab
  2. Move mouse to tabs, go right to click on newly opened tab
  3. Move mouse down into page (out of browser chrome)
  4. Modal is triggered
  5. Refresh page by clicking the "refresh" icon, or by highlighting the URL and pressing enter (i.e. entering browser chrome)
  6. Move mouse back down into page (out of browser chrome)
  7. Modal is triggered

Is mouseleave supported? http://www.quirksmode.org/dom/events/mouseover.html#t05

If that's not the problem, maybe you need to detect the movement direction (i.e. save each e.clientY on movement and compare against it on trigger)? Similar detection in https://github.com/kamens/jQuery-menu-aim

Incorrect behaviour when entering <html> (instead of leaving)

If you load the page when the mouse pointer is still in the bar of the browser (say, on the address field) and after the page is loaded you moved the mouse onto the page to start looking at the website (as you do), the modal will get activated (at least that's the behavior in Chrome Version 34.0.1847.116 m on Windows 7).
I think instead of mouseout, mouseleave should be used.

IE8 compatibility

As reported in #30, IE8 shows Object doesn't support property or method 'addEventListener'

Exit Intent

This is a brilliant alternative. But shouldn't this behave like bounceexchange where it captures exit intent, and not enter intent? How come all the demos ive seen on your site plus all other live sites has the code executed upon entry? Kind of defeats the purpose. Looks super spammy because it fires upon entry and makes me click X.

Rename library

ouiBounce should read ouibounce - the capital B is confusing.

not working with bootstrap

When we added

<link media="all" type="text/css" rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">

It would not work at all.

Improve test coverage

Ouibounce is growing in popularity and new edge-case requests are being submitted. We need to ensure the codebase is tested more thoroughly.

100% here we come!

Allow setting domain on cookie

Hey, considering you already have cookie expiration time, it might also be nice to have the ability to set the domain too. I have the popup appear on every page of site :)

New option: Set cookie name

The cookies generated with Ouibounce are named "viewedOuibounceModal" currently.
I'd like to see an option to set a custom cookie name.
This will allow sites to mention the cookie in their legal notice "as their own". A custom cookie name might look more likeable than "viewedOuibounceModal".

Add min-time before ouibounce fires

Allow a user to select how long before ouibounce fires. This will prevent the modal from firing right after loading if the mouse is near exit point.

Cookies tracking page not site

Is it be possible to change the cookies to affect the whole site and not only the page it was on? If a user exits the popup, I don't want them to see it for 5 days sitewide, not just on that page.

Thanks!

Questions

First off, thanks for this awesome library. I'm using it for a project and have amended ouiBounce so that the modal will activate when a user leaves from any side of the window.

I'm somewhat new to programming so I have a few question: some might have longer answers than other so feel free to only answer the ones you have time for.

  1. what do the first few lines do (function(root, factory) ... )? You mentioned that it is a UMD wrapper. Do you know of a good article that explains the basics of UMD?

  2. You chose mouseout as the event that your watching. Why didn't you choose mousemove?

  3. I want to contribute to ouiBounce, or at least publish my amendments, but I'm not sure what things like gulp are. I visited the site but it didn't clarify much for me.

Thanks,

Bez

Trouble getting $('#ouibounce-modal').hide(); to trigger (magento/bootstrap)

Can't seem to get .hide() to work correctly. My website is www.leafandspoon.com (I've set up oiubounce at www.leafandspoon.com/ordering). I'll paste the JS below. I really want to use this utility; any help would be greatly appreciated. Thanks

<script> // if you want to use the 'fire' or 'disable' fn, // you need to save OuiBounce to an object var _ouibounce = ouibounce(document.getElementById('ouibounce-modal'), { aggressive: true, timer: 0, callback: function() { console.log('ouibounce fired!'); } }); ``` $('body').on('click', function() { $('#ouibounce-modal').hide(); }); $('#ouibounce-modal .modal-footer').on('click', function() { $('#ouibounce-modal').hide(); }); $('#ouibounce-modal .modal').on('click', function(e) { e.stopPropagation(); }); ``` </script>

changing exit behaviour in test.html

In your test.html I would also propose changing the following

  $('body').on('click', function() {
    $('#ouibounce-modal').hide();
  });

to

  $('.underlay').on('click', function() {
    $('#ouibounce-modal').hide();
  });

so you can attach a ouibounce.disable(); function to when the modal gets closed to prevent aggressive popups. By using the body element, you can't bind any other functions to it.

Ouibounce pops up on all pages for my site

Hello,

I have integrated ouibounce for my site.
I have set cookie expiration to 30 days. When I visit the homepage of my site pop up fires & I close it. But again when I visit other page of my site, it pops up again. This happens on all pages for my site.

Below are settings I have done for my site:
var _ouibounce = ouibounce(document.getElementById('ouibounce-modal'), {
aggressive: true, //the modal will fire any time the page is reloaded, for the same user
timer: 0, //Set a min time before Ouibounce fires
sensitivity: 10, //The higher value, the more sensitive, and the more quickly the event will fire. Defaults to 20.
cookieExpire: 30, // disable ouibounce sitewide for 30 days
sitewide: true,
callback: function() { console.log('ouibounce fired!'); }
});

Any help would be appreciated!
Thanks in advance!

Regards.

Add a version of this to the README

From HN comments:

Author of the plugin here.
There's a few points I'd like to address/ clarify since I'm likely to have a different perspective than most HN users on this.

  1. Pop-ups are terribly annoying and provide a bad user experience. I agree, they're not the best. The question then remains "If they're so bad, then why do websites have them". Short answer: "Because it works. They drive sales. They drive engagement." I would pick a pop-up that fires when I'm about to leave the site v.s. one that shows on pageload or after X seconds any day of the week.

  2. Your marketing message is spammy and nobody likes spam. Very true too. It's extremely easy to abuse something like Ouibouce. I tried covering this in the readme: https://github.com/carlsednaoui/ouibounce#the-philosophy-beh....

Please use Ouibounce to provide value to your visitors. With tools like these it's very easy to create something spammy-looking. Not sure what I mean by provide value? Here are a few ideas to get your creative juices flowing: Free ebook, Upcoming webinar invite, Exclusive access to XYZ, A full educational course, Valuable content.

  1. This may increase revenue in the short term but will likely decrease goodwill in the long run. This one is so tricky and hard to measure. There's definitely a fine line that can be (very) easily crossed. My belief is that, so long as you add value to your visitors, you should be fine.
    If you want to continue the convo off HN, feel free to reach out @carlsednaoui

API changes to fire / disable OuiBounce

The API should allow a user to:

  • Fire the modal on demand with ouibounce(selector).fire()
  • Disable OuiBounce with ouiBounce(selector).disable() or simply ouiBounce().disable()

Mobile approach

I've been thinking about how to better display the modal window for mobile users... Probably a time without tapping activity would be ideal, but it's far from perfect. What are your thoughts on this?

Remove jquery dependency

Really, there's no reason this should depend on jquery at all. We should look into removing the jquery dep 😀

Use ouibounce without dummy object?

I want to have full control over what happens on exit (my own modal code, etc).

Right now I have to just make a dummy object, and put my regular code in the callback. Maybe we could just have something like calling ouibounce() on false will still trigger callbacks but wont try to mess with any elements?

Timer to track visitor for individual popup

Hi,
I think it could be nice to have a counter, who track the time, a visitor is online on the website. When he want to leave, the time could be used for individual messages in the popup.

if time =< 10 sec
Seems you don't like my site, would you like to tell me why? (Display a response form)

if time => 10 sec and =< 30 sec
bla, bla, .. (Display what ever)

if time => 30 sec
Seems you like my site, because you stay already a while here. You could sign up for my newsletter to stay up to date ... (Display newsletter form)

Think, you know what I mean ... I there a chance that you will be develop something like this?

Only works sporadically on Safari 7.0

I've been testing with Safari 7.0 (9537.71), and it hardly works.
I have to basically move the mouse out of the page container towards the top multiple times to get a reaction, even with the demo page.
Works fine in every other browser for me, so I'm a bit suprised.

Any ideas? Can anyone reproduce this? What can I provide to help track this down?

Small improvements

document.documentElement

  var cookies = document.cookie.split('; ');
  var ret = {};
  for (var i = cookies.length - 1; i >= 0; i--) {
    el = cookies[i].split('=');
    ret[el[0]] = el[1];  
  };
  return ret;

Idea: Show modal only when mouse cursor is not in the viewport

I'm reading the comments on Hacker News (https://news.ycombinator.com/item?id=7815324). Some people seem to not approve with the current behavior of your script.

I've posted an idea. I'm copy-pasting it here:

How about this: The modal shows up when you move the mouse out of the viewport (e.g. via the top edge), but then the modal closes immediately once the mouse cursor enters the viewport again. So, as long as (and only when) the mouse is above/outside the viewport, the modal is displayed.
Also, the modal doesn't have any buttons or fields. It's just displayed for informative purposes, e.g. to inform the user about a site update, or to point out a site feature.

I think, this would be a good enhancement. You could add this behavior via an option, e.g. "hide on re-enter".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.