How could I measure the time spent on the last page?

I found that I can’t measure the the time spent on the last page, so in my database they are always 0. As the pictrue, there is a new API to instead of using the heart beat timer.But I still don’t know when to use it.All I can think is use it in the onbeforeunload event, but it will also lead to too much HTTP request.So, is there any better solution?


You can check here on how to use the ping method (if you don’t want to use the existing heartbeat-feature):

Calling this should work: