標籤:code blog build debug 開始 level rate 最新 計數
項目中integrate了GA,碰到過一些問題:
1.Too many hits sent too quickly, rate limiting invoked
這個問題是發送hit(event/screen)太頻繁,超出了Google的限制。解決辦法是設定session timeout到一個合適的值,並且分段統一發送hit。
2.Google Play Services版本相容問題
由於裝置中Google Play Services版本太老,為了相容只得使用一個很老版本的Google Play Services。
compile ‘com.google.android.gms:play-services-base:6.5.87‘
這個版本中內建GA包,但包裡不含AnalyticsReceiver和AnalyticsService。
3.網路斷開後統計資料丟失
曾經出現過斷網一段時間然後網路恢複之後資料丟失。不但斷網期間的資料沒有,而且網路恢複後的資料不再繼續發送。
我更改了GoogleAnalytics Tracker的一些參數,但我還沒開始測試具體是哪項設定起了作用,這一點有待之後補充。
注意以下是Kotlin代碼
analytics.setLocalDispatchPeriod(resources.getInteger(R.integer.ga_dispatchPeriod)) if (BuildConfig.DEBUG) { analytics.logger.logLevel = com.google.android.gms.analytics.Logger.LogLevel.VERBOSE// analytics.setDryRun(true) } tracker = analytics.newTracker(applicationContext.resources.getString(R.string.ga_trackingId)) tracker.setSessionTimeout(60) tracker.enableExceptionReporting(true) tracker.enableAdvertisingIdCollection(true) tracker.enableAutoActivityTracking(true)
應該是localDispatchPeriod起的作用,但是要測試後才知道。
當然這個問題可能是由於GoogleAnalytics的版本問題。需要更新Google Play Services。可能如果使用最新的版本這個問題不會出現,這個我也還沒測試。
Android Google Analytics