Issue with screen tracking beforing opting out on flutter


In my Flutter app I have a situation where I need to track a screen right before disabling tracking. I use the following code to take care of that:

await FlutterPiwikPro.sharedInstance.trackScreen(screenName: 'My screen');
await FlutterPiwikPro.sharedInstance.dispatch();
await FlutterPiwikPro.sharedInstance.optOut(true);

This works for the most part, but on Android, sometimes (~20-40% of the time) the page view event is not actually sent. From what I understand, it seems that dispatch() is not fast enough so to speak, and the page view event is cleared from the dispatch queue by the optOput before being sent.

Am I understanding situation correctly? Can you suggest any workaround? Is there a chance of this being fixed?

Hi there!

This is not an error, but rather how it works by design. Enabling optOut clears the event queue. If an event is not sent before optOut is enabled (and sending depends on dispatchIntervalTime), unfortunately, it is lost.

We have plans to enhance the flexibility of this solution, but we are not yet able to specify exactly when this will be released. I encourage you to keep an eye on the changelog :smile: