"Tried to leave the website" event

Use the “Tried to leave the website” event to catch the attention of your visitors at the very last moment before they leave your website

The “Tried to leave the website” event will allow you to send a trigger message to users and catch their attention at the very last moment - when they move the cursor beyond the top border of your site.

The event works as follows:

  • The event script is triggered 5 seconds after the user opens the site;
  • When the user moves the mouse cursor above the site window, the “Tried to leave the website” event is triggered;
  • The event can be tracked again after 60 seconds;
  • The event will be recorded on any page of your website with the Dashly script installed.

If necessary, you can set up an event for an attempt to leave a specific page or section of your site. To do this, you need a script that you can add to the “Settings” – “Visitors data tracking” –  “Configure the JavaScript code” section:

Attempting to leave a specific page

if (window.location.href == 'PAGE URL') {
    (function () {
        function init() {
            setTimeout(addMouseout, 5000);
        }
        function addMouseout() {
            document.addEventListener('mouseout', mouseout);
        }
        function mouseout(e) {
            if (Math.round(e.x) >= 0 && Math.round(e.y) <= 0) {
                dashly.track('EVENT NAME');
                deleteEvent();
                setTimeout(addMouseout, 10000);
            }
        }
        function deleteEvent() {
            document.removeEventListener('mouseout', mouseout);
        }
        init()
    }())
}

❗ Replace the PAGE URL and EVENT NAME with relevant data. For example, you can add https://example.com/ as the url, and "Attempt to leave the main" as the name.

Attempt to leave the website's section

if (location.href.indexOf('PART OF SECTION URL') > -1) {
(function() {
     init()
     function init() {
         setTimeout(addMouseout, 5000);
     }
     function addMouseout(){
        document.addEventListener('mouseout', mouseout);
     }
     function mouseout(e) {
         if (Math.round(e.x) >= 0 && Math.round(e.y) <= 0) {
            dashly.track('EVENT NAME');
            deleteEvent();
            setTimeout(addMouseout, 10000);
        }
     }
     function deleteEvent() {
         document.removeEventListener('mouseout', mouseout);
     }
 }()) 
};

❗ This script also needs to be supplemented with data relevant to your site. Example - instead of PART OF SECTION URL, you can use /dresses/, and as the name of the event - "Visited the dresses section".

Powered by