PostHog / posthog-js-lite

Reimplementation of posthog-js to be as light and modular as possible.
https://posthog.com/docs/libraries
MIT License
70 stars 36 forks source link

Improve offline support #176

Closed marandaneto closed 8 months ago

marandaneto commented 9 months ago

Description

Context https://posthog.com/questions/offline-usage-1

It partially does. It persists the queue. The only thing is, that it doesn't:

pause flushing if the network is unreachable

this is nice to have since network connectivity callbacks only tell there's a cellphone signal or wifi connected but not necessarily the internet.

add messages back to the queue if the flush fails

this is a must, if an app is offline first, and it's always offline, the queue will try to be flushed and will remove the items from the queue, but it will fail since there's no connection at all, that slice of the queue will be lost if not restored.

johnslemmer commented 8 months ago

Hey @marandaneto I noticed this got closed with #177. Wondering if you can provide any more context on how offline support is improved. Is the queue now cached on the file system? Is there any limitation to the number events that this queue can store or length of time that an app can be offline for?

Thanks for working on this!!

marandaneto commented 8 months ago

All events will be cached if the device is offline, there's a timer flushing the events to the network, and the timer is configurable via flushInterval. If the device is offline, the events will remain cached, once the timer is triggered and there's network, the events will be sent and deleted from the local storage. Previously the events were deleted from the local storage even if flusing failed, so events were lost anyways.