How to Infer Exit Intent on Mobile Devices

Exit intent on desktop is pretty easy. The general concensus is that you track the user's cursor and when they are about to leave the bounding box of the web page, you trigger your exit intent script. This tends to work quite well, and gets you one last engagement with your customer before they bounce off of your site.

For mobile devices however, this method will not work. The obvious reason being that there is no cursor to track, and therefore no way to know when a user is about to scroll off of your page. Making matters worse, you have limited control over what you can do on mobile browsers due to security concerns. This means tracking the back button and tracking any clicks off of the browser window in general are off limits.

There is one last solution, however, which works most of the time and gives you one last chance to engage your users before they bouce. This solution is to do the following:

  • Keep track of the users scroll position.
  • When the user scrolls up, track their speed.
  • If the speed passes a certain threshold, fire your exit intent action.

This works because mobile web browsers require users to scroll upwards in order to view the URL bar. User's tend to perform this action swiftly, much faster than if they were trying to scroll up to read some content. This is the hook you need in order to reliably determine exit intent.

See below for some code that performs this task:


function myScrollSpeedFunction() {
  const delta = my_scroll();
  if(delta < -80){
    console.log('Perform your exit intent task here.');
  }
}

var my_scroll = (() => {
  let last_position, new_position, timer, delta, delay = 50; 

  function clear() {
    last_position = null;
    delta = 0;
  }

  clear();
  return () => {
    new_position = window.scrollY;
    if (last_position != null){
      delta = new_position - last_position;
    }

    last_position = new_position;
    clearTimeout(timer);

    timer = setTimeout(clear, delay);

    return delta;
  };
})()

$(document).on('scroll', myScrollSpeedFunction);

This code listens to the users scroll position, determins the speed, and, if the speed passes a certain threshold (-80 in this case) we trigger our exit intent action. You can adjust the threshold as needed if you prefer. Some other ideas are to wait until the user has scrolled at least 50% down the page before initializing this script. This way, you would only be engaging users who have been enjoying your content.

So let's do this.

Try Zigpoll and get the most out of your visitors.

Questions or Feedback?

We would love to hear from you.