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:
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".