简体   繁体   中英

Flush google analytics events manually with Google Play Services

Is there any way to manually flush all events in Google analytics queue, when Google Play Services is installed?

There is one method in the Android GA documentation: GoogleAnalytics.getInstance(getActivity().getBaseContext()).dispatchLocalHits();

But this method doesn't work with Google Play Services - the docs say :

public void dispatchLocalHits ()

Dispatches queued hits (view, events, or transactions) to Google Analytics if a network connection is available, and the local dispatching service is in use. This method only works if local dispatching is in use. Local dispatching is only used in the absence of Google Play services on the device. In general, applications should not rely on the ability to dispatch hits manually.

When Google Play service is available hits from the application are send over to the service without any delay (except for the processing time that should not take longer then milliseconds). Once the data is send over to the service your application is not involved in the delivery. Your application process can safely be terminated and the hits will still be uploaded to the Analytics. The service itself will periodically dispatch the collected data from multiple application in compressed batches. Individual applications don't have control on the service dispatch schedule. In general the hits would be uploaded over the network within few minutes after they are reported by the application.

Almost any device that has Google Play store installed will have Google Play services. Chances are your app is running on a Google Play device. Amazon Fire phone and many of the carrier sponsored devices in China will not have Google Play services.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM