How to track user time on site

前端 未结 5 1739
渐次进展
渐次进展 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:19

    There really isn't an effective way to do this with PHP, as PHP is server-side and provides no way of determining when the page was closed. You need to use javascript to determine this.

    What I would do is use javascript to start a timer on window.onload and then end the timer on window.onunload. Then you can store the data and do what you want with it.

提交回复
热议问题