Amplitude-TypeScript icon indicating copy to clipboard operation
Amplitude-TypeScript copied to clipboard

Add `setOffline()` to enable custom offline logic

Open Mercy811 opened this issue 1 year ago • 4 comments

Summary

This issue is to collect customer requests on adding setOffline().

Amplitude Browser SDK supports offline mode out of the box by https://github.com/amplitude/Amplitude-TypeScript/pull/644.

Leave a comment under this issue with the use causes when and why you need this feature. We will prioritize it and fit into our roadmap.

Mercy811 avatar Jan 29 '24 17:01 Mercy811

We're using the offline property to dynamically pause sending events. This allow us to capture events in the unsent queue, until the customer answers our consent popup (which can be delayed), and then if they give consent, we can unpause the queue.

It's a bit unfortunate the feature is called offline, instead of using something more generic, like "pause", as it could be used by multiple plugins if it wasn't only associated with offline.

Renaming it to something like "paused" might be better, and then allow different plugins to set their own locks, and if any lock is set, events won't be sent until all locks are lifted.

Multiply avatar Jan 29 '24 17:01 Multiply

Hi @Multiply, I think for this scenario particularly you can amplitude.track() first. Then if user accepts your consent, call amplitude.init() to initialize the SDK. In this way, events are tracked and are in storage without actually being sent to Amplitude until user consent and init the SDK.

Mercy811 avatar Jan 29 '24 18:01 Mercy811

@Mercy811 consent can be changed during runtime, and we'd still have to pause events in that scenario.

Multiply avatar Jan 29 '24 19:01 Multiply

@Multiply I see. I will keep you updated once we have the feature in our roadmap.

Mercy811 avatar Jan 29 '24 19:01 Mercy811