where i need to store user's time spent on page. (this is ignoring idle time, i have made javascript code to get timings).
I need help with how i can send this data to backend.
I am thinking of using below approach.
Use indexDB to store the data.
In set interval of 10 seconds, i will just store the time and additional info in indexDB as an object.
I also do the same when beforeunload event is triggered. SO i wont lose any data.
Now to send this data to backend, i will use setInterval to check no of records in indedxDB and once they are more or equal to 100, I will send to backend. (this is to avoid too many small requests).
Does this approach sound good? Or am i missing anything that could go wrong?
This is a good usecase for that sendBeacon API
Обсуждают сегодня