Android Google Analytics

Posted by ibenot on Stack Overflow See other posts from Stack Overflow or by ibenot
Published on 2012-04-07T11:26:13Z Indexed on 2012/04/07 11:29 UTC
Read the original article Hit count: 231

Filed under:
|
|
|
|

I'm trying to use Google Analytics in my Android application with Google Configuration

  1. Add .jar in my project
  2. Insert this in AndroidManifest

  3. Add this in my java file

public class MainActivity extends Activity {

GoogleAnalyticsTracker tracker;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

            tracker = GoogleAnalyticsTracker.getInstance();
            tracker.startNewSession("My-UA–XXXXXXXX", this);


            setContentView(R.layout.main);
            Button createEventButton = (Button)findViewById(R.id.NewEventButton);
            createEventButton.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View v) {
                tracker.trackEvent(
                    "Clicks",  // Category
                    "Button",  // Action
                    "clicked", // Label
                    77);       // Value
              }
            });

            setContentView(R.layout.main);

            Button createPageButton = (Button)findViewById(R.id.NewPageButton);
            createPageButton.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View v) {
                // Add a Custom Variable to this pageview, with name of "Medium" and value "MobileApp" and
                // scope of session-level.
                tracker.setCustomVar(1, "Navigation Type", "Button click", 2);
                // Track a page view. This is probably the best way to track which parts of your application
                // are being used.
                // E.g.
                // tracker.trackPageView("/help"); to track someone looking at the help screen.
                // tracker.trackPageView("/level2"); to track someone reaching level 2 in a game.
                // tracker.trackPageView("/uploadScreen"); to track someone using an upload screen.
                tracker.trackPageView("/testApplicationHomeScreen");
              }
            });

            Button quitButton = (Button)findViewById(R.id.QuitButton);
            quitButton.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View v) {
                finish();
              }
            });

            Button dispatchButton = (Button)findViewById(R.id.DispatchButton);
            dispatchButton.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View v) {
                // Manually start a dispatch, not needed if the tracker was started with a dispatch
                // interval.
                tracker.dispatch();
              }
            });




}

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

}

==> And it's ok, no error, compiling and executing but i have created my ua account yesterday (more 24h) and i have nothing in my google analytics panel.

My Question : is there an error in my code or i want to wait again ? Live trafic works for Android application (like tradicional website) ??? I have no information about Live trafic (when i play my app, i would like to show the number of person using my application) and Saved trafic (with viewed pages, time)

Thank you for your replies and excuse my poor english :)

bye

© Stack Overflow or respective owner

Related posts about java

Related posts about android