While using Google Analytics for android, if i use
tracker.start("UA-YOUR-ACCOUNT-HERE", 20, this)
then every 20 seconds, events will be dispatched automatically even if i dont do it manually using
tracker.dispatch()
My Question is, what happens if the user quits my application within 20 secs? will it be dispatched?
or do i have to dispatch all the pending events manually when the user is trying to exit?
You don't have to do anything- The events get stored and will be lumped together with the next dispatch that occurs in your app (presumably the next time the user fires up the application).
Note that Analytics servers timestamp the hit based on when they receive the data, not based on when the event actually occurred- So if your users use the app for a couple minutes a day, visits which occurred on the 10th might show up in Analytics on the 11th, etc.
Update: To clarify on the behavior when tracker.stop() is called, it does not dispatch pending events at that point. They stay in an internal sqlite database, and are the first to go out when a dispatch is called in the next run of your application. The reason they aren't fired when the tracker is stopped is that it would add time to the Activity being destroyed, making the app feel less "snappy" on exit. This is also the reason you should think carefully before dispatching in the onDestroy method.
tracker.stop() does not dispatch the data. My advice is to also put tracker.dispatch() in the onDestroy() method
@Override
protected void onDestroy() {
super.onDestroy();
tracker.dispatch();
// Stop the tracker when it is no longer needed.
tracker.stop();
}
source: http://www.google.com/support/forum/p/Google%20Analytics/thread?tid=70a919f5b097f5dc&hl=en
It is recommended that you stop the tracker when your app is destroyed using the following;
@Override
protected void onDestroy() {
super.onDestroy();
// Stop the tracker when it is no longer needed.
tracker.stop();
}
I would assume this would dispatch any waiting events.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With