简体   繁体   English

如何在移动浏览器上检测退出意图?

[英]How can I detect exit intent on a mobile browser?

I'm working on a solution to detect exit intent on safari mobile.我正在研究一种解决方案来检测 safari mobile 上的退出意图。 (or any mobile browser for that matter) (或任何与此相关的移动浏览器)

On desktop I can track curser movement and when the user breaks the plane of the webpage I can initiate a pop up.在桌面上,我可以跟踪光标移动,当用户打破网页平面时,我可以启动一个弹出窗口。 See http://www.quicksprout.com/about/ as an example.http://www.quicksprout.com/about/为例。 Move your curser up to the back button on the browser and as soon as your curser breaks the webpage a pop up will appear.将光标向上移动到浏览器上的后退按钮,一旦光标断开网页,就会出现一个弹出窗口。 How can I solve this in a mobile environment?如何在移动环境中解决此问题?

Is there any way to detect when someone clicks the Safari address bar and before the favorites screen appears I can launch a pop up then?有什么方法可以检测到有人点击了 Safari 地址栏,然后在出现收藏夹屏幕之前我可以启动一个弹出窗口吗?

Thank you in advance for the help.预先感谢您的帮助。

I know this is over a year later, but maybe my answer might still help someone in the future.我知道这是一年多了,但也许我的回答将来可能仍然对某人有所帮助。

On some of my sites, I found that mobile exit intent often consists of a slight upward scroll before the user hits their back button.在我的一些网站上,我发现移动退出意图通常包括用户点击后退按钮之前的轻微向上滚动。 For example, users often scroll down the page quite a bit while consuming content, but when they're ready to leave they might scroll upwards slightly (say 5-10% of the page height), and then they'll go hit the back button or close the tab.例如,用户在消费内容时经常向下滚动页面,但是当他们准备离开时,他们可能会稍微向上滚动(比如页面高度的 5-10%),然后他们会回滚按钮或关闭选项卡。

I use that knowledge to pop up a newsletter sign up form on some of my content sites, and it actually works well without annoying the user.我利用这些知识在我的一些内容网站上弹出一个时事通讯注册表格,它实际上运行良好而不会打扰用户。 So if I ever detect that a user scrolled down at least 50% of my page, then back up by at least 5%, I hit them with a popup since I think they liked my content but are ready to exit the page.因此,如果我检测到用户至少向下滚动了我页面的 50%,然后又向后滚动了至少 5%,我会弹出一个弹出窗口,因为我认为他们喜欢我的内容但已准备好退出页面。 I wrote some simple Javascript that actually lets me detect such behavior at https://github.com/shahzam/DialogTriggerJS我写了一些简单的 Javascript,实际上让我在https://github.com/shahzam/DialogTriggerJS 上检测到这种行为

Not sure if that's the exact answer you're looking for, but hope that helps a bit!不确定这是否是您正在寻找的确切答案,但希望对您有所帮助!

I just came back from a long trip around the web with the same goal in mind however as of now - you really are not able to detect if a user clicks on the address.我刚刚带着相同的目标从网上长途旅行回来,但到目前为止 - 你真的无法检测到用户是否点击了地址。

However I found out that you can look for patterns that users are making before they are ready to leave your website or abandon shopping cart.但是我发现您可以在用户准备离开您的网站或放弃购物车之前寻找他们正在制作的模式。 Here is show how we solved this and made mobile exit intent work on all mobile devices in case if the user quickly scrolls back up the page since that can be a sign that shows that the user has lost interest in our content and might want to leave.这里展示了我们如何解决这个问题并使移动退出意图在所有移动设备上工作,以防用户快速向上滚动页面,因为这可能表明用户对我们的内容失去兴趣并可能想要离开.

  1. Detecting if the user is on a mobile device.检测用户是否在移动设备上。 This part is rather simple - we use Javascript to check if the event is "touchstart" and if so, we are adding a class to our body tag:这部分相当简单——我们使用 Javascript 来检查事件是否为“touchstart”,如果是,我们将向 body 标签添加一个类:

     jQuery(document).on('touchstart', function(){ $(body).addClass('on-mobile-device'); });
  2. Detecting the scroll direction, scroll speed and displaying Exit Intent popup:检测滚动方向、滚动速度并显示 Exit Intent 弹出窗口:

     function myScrollSpeedFunction(){ if( jQuery('body').hasClass('on-mobile-device') ){ if(my_scroll() < -200){ //Your code here to display Exit Intent popup console.log('Must show mobile Exit Intent popup') } } } var my_scroll = (function(){ //Function that checks the speed of scrolling var last_position, new_position, timer, delta, delay = 50; function clear() { last_position = null; delta = 0; } clear(); return function(){ 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; }; })(); jQuery(document).on('scroll', myScrollSpeedFunction );

This is basically it.基本上就是这样。 This way you are not interrupting the user's flow since the user has already finished looking at the content and going up very quickly and we can present him with a message.这样你就不会打断用户的流程,因为用户已经看完了内容并且很快就上来了,我们可以向他展示一条消息。

What we have done ourselves besides this code is to make sure our Exit Intent popup is displayed only in case if the user has got a product in his shopping cart since we are suggesting to save the users shopping cart and remind about his abandoned cart via email.除了此代码之外,我们还自己做的是确保我们的退出意图弹出窗口仅在用户的购物车中有产品时才显示,因为我们建议保存用户的购物车并通过电子邮件提醒他放弃的购物车. You can test it out on our product page here: https://www.cartbounty.com , just remember to add a product to the shopping cart before you test drive it on your mobile device.您可以在我们的产品页面上进行测试: https : //www.cartbounty.com ,只需记住在您的移动设备上试驾之前将产品添加到购物车。

At least on mobile safari, you're looking for the window.onpagehide function.至少在移动 safari 中,您正在寻找window.onpagehide功能。 This event will fire immediately after the page is hidden.此事件将在页面隐藏立即触发。

Here is a snippet showing this code in action:这是一个片段,显示了此代码的运行情况:

<!DOCTYPE html>
<html>
    <head>
        <script> window.onpagehide = function(e) { alert("Don't go! I'm lonely!"); }</script>
    </head>
    <body>
    </body>
</html>

Unfortunately, it looks like if you want an event to fire before the page is hidden, you're out of luck, because mobile Safari halts execution of everything on the page when the user clicks on the address bar.不幸的是,如果您希望在页面隐藏之前触发一个事件,那么您就不走运了,因为当用户单击地址栏时,移动版 Safari 会停止执行页面上的所有内容。 This means that you cannot, for example, monitor the page height to see if the user is typing on the keyboard (as they would be if they clicked the address bar).例如,这意味着您无法监视页面高度以查看用户是否在键盘上键入(就像他们单击地址栏时那样)。

Some simple code to detect exit intent on a mobile device.一些简单的代码来检测移动设备上的退出意图。

It detects exit intent through the speed of the user's upwards scroll.它通过用户向上滚动的速度检测退出意图。

It delays 10 seconds before enabling.它在启用前延迟 10 秒。 You probably should make it about 30 seconds if you only want to show your exit intent popup to people who are really interested in your content.如果您只想向真正对您的内容感兴趣的人显示您的退出意图弹出窗口,您可能应该将其设置为大约 30 秒。

setTimeout(() => {
  document.addEventListener("scroll", scrollSpeed);
}, 10000);


scrollSpeed = () => {
  lastPosition = window.scrollY;
  setTimeout(() => {
    newPosition = window.scrollY;
  }, 100);
  currentSpeed = newPosition - lastPosition;
  console.log(currentSpeed);

  if (currentSpeed > 160) {
    console.log("Exit intent popup triggered");
    document.removeEventListener("scroll", scrollSpeed);
  }
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM