[FR] ThreadedAnalyticsDestination - flushing events before closing

Could we get some way to flush the event queue of a ThreadedAnalyticsDestination?

Currently, any unsent events are stored to a file in the TAD’s destructor, which means that any last-minute events aren’t sent until the next run. This means we always have way more session-start events than session-end events which can make it hard to accurately track user flows.

I have a very hacky workaround (see below), but it’d be nice to have a more “official” approach.

void AnalyticsDestination::flushEventsFor (juce::RelativeTime duration)
    startAnalyticsThread (0);
    juce::Thread::sleep (static_cast<int> (duration.inMilliseconds ()));

One problem with this hack approach is that it’s a waste of time if the event queue is already empty, so it’d be nice to at least have a way to query the number of remaining events so I can close as soon as the queue is empty, or the timeout is up, whichever comes first.

1 Like