Actually I think I might found the way to make it works. Reading the documentation: https://developers.google.com/analytics/devguides/collection/android/v4/dispatch
By default, data is dispatched from the Google Analytics SDK for
Android every 30 minutes.
Yes, my thoughts were "What???? 30 minutes? Is not suppose to be real time?" Anyway, reading a bit more:
To set the dispatch period programmatically:
// Set the dispatch period in seconds.
GoogleAnalytics.getInstance(this).setLocalDispatchPeriod(15);
To set the dispatch period in the XML configuration file:
<integer name="ga_dispatchPeriod">30</integer>
What more...
Setting a negative value will disable periodic dispatch, requiring that you use manual dispatch 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);
Ok, maybe you have found a controversial here, negative value or less than 1? I tried, it is less than 1! (0 or negative number will disable periodic dispatch).
If you prefer then the manual dispatch, that would be, for example:
tracker.setScreenName(TAG);
tracker.send(new HitBuilders.AppViewBuilder().build());
GoogleAnalytics.getInstance(getActivity().getBaseContext()).dispatchLocalHits();
Notice that you can call dispatchLocalHits() whenever you want (even make a button that calls that function). By the way, that piece of code it's on my fragments (in the onResume() method).
Also the documentation says:
If a user loses network access or quits your app while there are still hits waiting to be >dispatched, those hits are persisted in local storage. They will be dispatched the next >time your app is running and dispatch is called.
But I was not sure if this applies to both manual and periodic dispatch. I tried it, both seem to be working :)