How to track user time on site

前端 未结 5 1847
渐次进展
渐次进展 2021-01-30 14:49

I\'m looking to track users average time on a website (in the same way that Google analytics does) for internal administration.

What\'s the easiest way to do this?

5条回答
  •  青春惊慌失措
    2021-01-30 15:33

    You can get the time in next ways:

    1. Once user visit your site, save current time at cookie as "visited", and at next visit you can grab it, if it was set.
    2. And more expensive method: when the page loads, start js timer, and on page unload send to server time which user sent and save it to db.
    3. And if window.unload does not work at Opera, you can send time to server every 5 seconds, and stores it to DB.

    If you need, I can write an example script.

    UPDATE:

    
    
        
            Collect time
            
            
        
        
    
        
    
    

    And backend script:

    But as I said it wouldn`t work at Opera browser

提交回复
热议问题