Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve offline support #176

Closed
marandaneto opened this issue Feb 12, 2024 · 3 comments · Fixed by #177
Closed

Improve offline support #176

marandaneto opened this issue Feb 12, 2024 · 3 comments · Fixed by #177

Comments

@marandaneto
Copy link
Member

marandaneto commented Feb 12, 2024

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
Copy link

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
Copy link
Member Author

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.

@rafaellehmkuhl
Copy link

rafaellehmkuhl commented Dec 6, 2024

It is important to mention that for the queue to be persistent between sessions (e.g.: the app is used offline several times, being opened and closed, and at some point it is used online), the user must set the persistence key to localStorage in the initial configuration:

PostHog.posthog = posthog.init('your_key', {
  api_host: 'https://us.i.posthog.com',
  persistence: 'localStorage',
  persistence_name: 'posthog-persistent-queue-or-the-name-you-prefer'
})

EDIT: I'm testing here and it seems like not even in this case the queue is persisted between sessions. @marandaneto am I right to understand that? I've opened #324 to discuss it further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants