analytics_flutter
analytics_flutter copied to clipboard
If event upload fails, try to upload the event again
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?
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