Flush google analytics events manually with Google Play Services

时光毁灭记忆、已成空白 提交于 2019-12-11 02:35:08

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/28701628/flush-google-analytics-events-manually-with-google-play-services

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!