Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Analytics for Android issue with dispatch()

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?

like image 873
amithgc Avatar asked Nov 09 '10 12:11

amithgc


3 Answers

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.

like image 134
Alexander Lucas Avatar answered Nov 02 '22 21:11

Alexander Lucas


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

like image 4
John Oleynik Avatar answered Nov 02 '22 21:11

John Oleynik


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.

like image 2
CodeChimp Avatar answered Nov 02 '22 21:11

CodeChimp