Search This Blog

31 May 2010


Use the Alert Dialogs example as a starting point.....

Add this icon to your src\main\android\res\drawable directory

I grabbed that icon from the Tango project, but had to change the filename to be compatable with Android.

Then from the Google Analytics example, create an analytics profile, update your pom.xml and AndroidManifest.xml

Instead of putting the tracker code directly into the onCreate method, let's move that into the "I Accept!" button.  Note the change to onDestroy as well!

public class DisclaimerTestActivity extends Activity {
    private static String TAG = "DisclaimerTest";
    private GoogleAnalyticsTracker tracker = null;

    public void onCreate(Bundle savedInstanceState) {

        AlertDialog dialog = new AlertDialog.Builder(this).create();
        dialog.setMessage("In order to provide support for this application, we reserve the right to anonymously track and report usage information in this application.  We will track which parts of the application are popular but will not track who you are or what you type / look at.");
        dialog.setButton("I Accept!", new DialogInterface.OnClickListener(){
            public void onClick(DialogInterface dialogInterface, int i) {
                tracker = GoogleAnalyticsTracker.getInstance();
                tracker.start("UA-YOUR-ACCOUNT-HERE", DisclaimerTestActivity.this);
        dialog.setButton2("No Way!", new DialogInterface.OnClickListener(){
            public void onClick(DialogInterface dialogInterface, int i) {

    protected void onDestroy()
        if(tracker != null) tracker.stop();

    // track("Clicks", "Button", "clicked", 77
    private void track(String category, String action, String label, int value)
        tracker.trackEvent(category, action, label, value);

    // track("/testApplicationHomeScreen");
    // track("/download");
    private void track(String page)

    // Allows sending in bulk by queuing up multiple tracks before calling dispatch
    // timestamps based on when dispatch is called
    private void dispatch()

Redeploy (mvn clean install).  Now, if you accept the disclaimer it will do analytic notifications (which can take up to 24 hours to show up).  If you cancel, it will just close the app.

No comments:

Post a Comment