Google Analytics for Android releases with submit ()

When using Google Analytics for Android, if I use

tracker.start("UA-YOUR-ACCOUNT-HERE", 20, this)

then every 20 seconds events will be sent automatically, even if I don’t do it manually using

 tracker.dispatch() 

My question is: what happens if a user leaves my application within 20 seconds? will it be sent?

or do I need to send all pending events manually when a user tries to exit?

+7
android google-analytics
source share
4 answers

tracker.stop () does not send data. My advice is also to include puter.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

+4
source share

You do not have to do anything. Events will be saved and combined with the next dispatch that appears in your application (presumably the next time the user launches the application).

Please note that Google Analytics servers mark a date based on when they receive the data, and not based on when the event occurred. For example, if your users use the application for a couple of minutes a day, you may see visits that occurred on the 10th in Analytics on the 11th, etc.

Update: To find out when tracker.stop () is called, it does not send pending events at this point. They remain in the sqlite internal database and exit first when sending is called the next time your application starts. The reason that they do not start when the tracker is stopped is because it will add time to kill the Action, which will make the application less β€œfast” on exit. This is also the reason you should think carefully before submitting to the onDestroy method.

+6
source share

It is recommended that you stop the tracker when your application is destroyed using the following:

  @Override protected void onDestroy() { super.onDestroy(); // Stop the tracker when it is no longer needed. tracker.stop(); } 

I would suggest that this would send any pending events.

+2
source share

This code will help you ...

 public class TestActivity extends Activity { GoogleAnalyticsTracker tracker; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); tracker = GoogleAnalyticsTracker.getInstance(); // Start the tracker in manual dispatch mode... tracker.startNewSession("UA-33332745-1", this); setContentView(R.layout.main); Button createEventButton = (Button)findViewById(R.id.NewEventButton); createEventButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { tracker.trackEvent( "Clicks", // Category "Button", // Action "clicked", // Label 77); // Value } }); Button createPageButton = (Button)findViewById(R.id.NewPageButton); createPageButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { // Add a Custom Variable to this pageview, with name of "Medium" and value "MobileApp" tracker.setCustomVar(1, "Medium", "Mobile App"); tracker.trackPageView("/testApplicationHomeScreen"); } }); Button quitButton = (Button)findViewById(R.id.QuitButton); quitButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { finish(); } }); Button dispatchButton = (Button)findViewById(R.id.DispatchButton); dispatchButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { tracker.dispatch(); } }); } protected void onDestroy() { super.onDestroy(); // Stop the tracker when it is no longer needed. tracker.stopSession(); } } 
+1
source share

All Articles