The front-end buried points count the length of stay on the page.

recently encountered a problem when doing the front-end burying point, the need is to count the length of time the page stays and the time it takes to leave the page.

so I want to trigger a buried point request when the user leaves the current page. I try to use the beforeunload event, but there are always some problems.

I wonder how other plug-ins count the length of stay on the page, whether the front end records the time when the user leaves the page, or the time it takes to enter the second page in the background minus the exposure time of the first page.
ask God to tell me, thank you!

Oct.08,2021

in fact, there is no need for any event at all, as you said, beforeunload, can get all kinds of timestamps of the life cycle of the page with window.performance.timing. For details, please see https://www.cnblogs.com/sunsh.
. It is recommended to use domComplete (the time node where the domComplete:html document is fully parsed) as the start time time1,. When the user clicks to jump to another page, immediately obtain the current timestamp time2, before the event jumps, and then submit the time1,time2 to the backend using ajax,post. Wait for the ajax callback, and then jump to the page.
subtract the time1 timestamp from the time2 timestamp, which means the stay is long.
suggest adopting the answer, thank you!

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e5054e-656bd.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e5054e-656bd.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?