Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8518305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:56:37+00:00 2026-06-11T05:56:37+00:00

I want to implement Google Analytics for my sample app in Android. How can

  • 0

I want to implement Google Analytics for my sample app in Android. How can I view the data or analytic changes in server & how can I send the custom variables to server side. What should I do after that?

public class TestActivity extends Activity {

  GoogleAnalyticsTracker tracker;

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

    tracker = GoogleAnalyticsTracker.getInstance();

    // Start the tracker in manual dispatch mode...
    tracker.startNewSession("UA-34709489-1", this);
    tracker.trackPageView("/HomeScreen"); 
    // ...alternatively, the tracker can be started with a dispatch interval (in seconds).
    //tracker.startNewSession("UA-YOUR-ACCOUNT-HERE", 20, 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
      }
    });

    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"
        tracker.setCustomVar(1, "Navigation Type", "Button click",2);
        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();
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:56:38+00:00Added an answer on June 11, 2026 at 5:56 am

    Refer this: Google Analytics For Android

    In details, apart from including the analytic jar from the above link, you need to use the following code:

    import android.content.Context;
    import com.google.android.apps.analytics.GoogleAnalyticsTracker;
    
    /**
     * @description Google analytics This class is used to create Google Analytics
     *              tracker instance. This will track actions performed in the
     *              application.
     */
     public final class GoogleAnalytics {
    
    private static GoogleAnalyticsTracker tracker;
    private static GoogleAnalytics googleAnalytics = null;
    private final static int VALUE = -1;
    private final static String CATEGORY = "Application Name";
    
    /**
     * 
     * @param context
     * @return
     */
    public static GoogleAnalytics getGoogleAnalyticsInstance(Context context) {
        if (googleAnalytics == null) {
            googleAnalytics = new GoogleAnalytics(context);
            tracker = GoogleAnalyticsTracker.getInstance();
            tracker.startNewSession(--enter your reg number here--, 10, context);
        }
        return googleAnalytics;
    
    }
    
    private GoogleAnalytics(Context context) {
    }
    
    /**
     * Stop current session
     */
    public void stopSession() {
        tracker.stopSession();
        googleAnalytics = null;
    }
    
    /**
     * Tracks Event of actions performed
     * 
     * @param action
     * @param label
     */
    public void trackEvent(String action, String label) {
        tracker.trackEvent(CATEGORY, // Category
                action, // Action
                label, // Label
                VALUE);
    }
       }
    

    Now anywhere you need to track an event just call:

    GoogleAnalytics.getGoogleAnalyticsInstance(this).trackEvent("Event Name", "Event Desc");
    

    To get your application registraion number see this:
    Register for Google Analytics

    Also remeber to call following when you want a single session to end:

    GoogleAnalytics.getGoogleAnalyticsInstance(this).stopSession();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement this new method of Google Analytics, I want to conditinally
I want to implement a UI on my Android app that feels like the
I want to implement heat maps over Google maps with my own data beyond
I'm developing an App using Google's UI design guidelines, so I want to implement
I want to implement an in-app purchasing mechanism that supports both Google checkout and
I want to implement a collapsible view, exactly like the one from Google Play
I want to implement a Google Map on my .NET page. I used the
I want to implement in my webpage something similar to google search page. The
I'm trying to implement the Candlestick Google Chart, but I want to be able
I want to implement the Google custom search API with Greasemonkey, and so far

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.