segmentio / analytics_flutter

The hassle-free way to add Segment analytics to your Flutter app.
MIT License
26 stars 33 forks source link

If event upload fails, try to upload the event again #72

Open Jay-57blocks opened 2 months ago

Jay-57blocks commented 2 months ago

Since I am developing the LOT project, most of the time it interacts with hardware devices and cannot access the Internet. I want to monitor the availability of the network and let it upload all events. My current code is like this. Is there a more recommended way to write it?


   _connectivity.onConnectivityChanged.listen((event) {
      final accessNetwork = event == ConnectivityResult.mobile;
      _onAccessNetworkChanged(accessNetwork);
  });

 void _onAccessNetworkChanged(bool accessNetwork) {
    if (accessNetwork) {
      _analytics.addFlushPolicy([ImmediatelyFlushPolicy()]);
    } else {
      _analytics.removeFlushPolicy(_analytics.getFlushPolicies());
    }
  }

class ImmediatelyFlushPolicy extends FlushPolicy {
  @override
  start() {
    shouldFlush = true;
  }
}

I found that if uploading an event fails, it will not retransmit the event. Is there any way to upload the event again? Or can you know whether each event was uploaded successfully and re-upload these events through custom code?

image
edsonjab commented 2 months ago

Hi @Jay-57blocks you can create your own plugin or policy to identify that part of process, you can check our documentation about that HERE