In fact, I think I could find a way to make it work. Read the documentation: https://developers.google.com/analytics/devguides/collection/android/v4/dispatch
By default, data is sent from the Google Analytics SDK for Android every 30 minutes .
Yes, my thoughts were "What ?? 30 minutes? It is not assumed that you are in real time?" Anyway, reading a little more:
To set the sending period for the program period:
// Set the dispatch period in seconds. GoogleAnalytics.getInstance(this).setLocalDispatchPeriod(15);
To set the send period in the XML configuration file:
<integer name="ga_dispatchPeriod">30</integer>
What else...
Setting a negative value will disable periodic sending, requiring you to use manual sending if you want to send any data to Google Analytics.
// Disable periodic dispatch by setting dispatch period to a value less than 1. GoogleAnalytics.getInstance(this).setLocalDispatchPeriod(0);
Well, maybe you find the questionable here, a negative value or less than 1? I tried, it is less than 1! (0 or a negative number will disable periodic sending).
If you prefer manual sending, it will be, for example:
tracker.setScreenName(TAG); tracker.send(new HitBuilders.AppViewBuilder().build()); GoogleAnalytics.getInstance(getActivity().getBaseContext()).dispatchLocalHits();
Note that you can call dispatchLocalHits () whenever you want (even create a button that calls this function). By the way, this part of the code is on my snippets (in the onResume () method).
The documentation also says:
If a user loses access to the network or leaves your application while there are still hits awaiting sending> sending, these hits are stored in local storage. They will be sent the next time your application is launched and sending is called.
But I was not sure that this applies to both manual and periodic dispatch. I tried, both seem to work :)