开发者

Using Google Analytics with Android - Data Usage

I've just added the required code to my Android app and released the update to market.

Thinking about it though, I wondered what the data usage was like. Analytics doesn't send the tracking data immediately, instead it sends cached data at a set time interval or manually with a call in yo开发者_开发技巧ur app.

In my app I do this every minute. I don't think this is excessive as my app probably won't be open for long periods of time between uses.

I have three activities in my app that each track as a pageview. If the main activity is loaded it is tracked once. If nothing happens (i.e. no reloads or loads of other activities) after this one tracked pageview, will it continue to send data or will it know nothing has changed and therefore only send further data when more pageviews are tracked?

Cheers


Google's library works on a queue system. That being when you activity is loaded you have a call to track that page view. That single call will place a page view on the queue. Your timing code will take everything out of the queue and send it to the server. Once it's sent there is nothing left on the queue and it won't send anything when executes again in a minute. As long as there is nothing in that queue the polling cycle will look at the queue see there's nothing and go back to sleep waiting for another minute before checking to see if something new is there and repeating.

If the user shuts down the app and reloads it. Then the code will execute that page track statement again putting something back on the queue, and then it will send another page view.

It's important where you put that page track statement so that it sends it once per start and not during resume() or some other life cycle method that could be executed lots of times as the user jumps between views.

It won't keep sending the page view over and over on every polling cycle of your pumping thread.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜