Detect and temporize interactions within the website

0

Can someone help me to know the time between when a person clicks on a button (that opens a window with an external website), until they close it or return to my website?

The aim of this code is to obtain a time to determine if a person has been on a website enough time to perform a certain action.

I have searched in many places in all possible ways and in several languages, but all I find are methods that only work if the open web is yours, and it is not my case:

window.onbeforeunload = function(){
    //acción
}

If you can not write me the code, I also use a source to find out or the name of the " method " to use to find information about its use.

Thank you very much

    
asked by ByBrayanYT - Tops y más 15.05.2018 в 20:06
source

1 answer

0

I'm not sure this solves your problem 100%, but you can try. It occurs to me that you can "play" with the focus and blur events to be able to control when the user returns or leaves your screen.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script>
    $(document).ready(function(){
      $(window).on('blur', function(){
        console.log('se ha perdido el foco');
      });

      $(window).on('focus', function(){
        console.log('tiene el foco');
      });
    });
  </script>
</body>
</html>
    
answered by 15.05.2018 / 20:38
source