Pravinsingh Waghela Pravinsingh Waghela - 1 year ago 94
Android Question

How to integrate Google Analytics in Android app

Hi I am trying to integrate the Google Analytics but I am not able to find any analytics data that shows on the Google Analytics Account of mine. I am using the link mention below:- link 1

some link 1

some link 2 link 2

But I am not able to get the result, nor the correct path/way or proper and Detailed Tutorial for how to integrate the Google Analytics in android app.

My code is as follows:-

public class MainActivity extends Activity {
GoogleAnalytics tracker;

protected void onCreate(Bundle savedInstanceState) {

// Get tracker.
Tracker t = ((AnalyticsHelper) MainActivity.this.getApplication()).getTracker(
// Set the dispatch period in seconds.

protected void onStart() {
// Set the dispatch period in seconds.

protected void onStop() {

My Analytics Helper class is as follows:-

public class AnalyticsHelper extends Application {

// The following line should be changed to include the correct property id.
private static final String PROPERTY_ID = "UA-xxxxxxxx-x"; // My Property id.

public static int GENERAL_TRACKER = 0;

public enum TrackerName {
APP_TRACKER, // Tracker used only in this app.
GLOBAL_TRACKER, // Tracker used by all the apps from a company. eg: roll-up tracking.
ECOMMERCE_TRACKER, // Tracker used by all ecommerce transactions from a company.

HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();

public AnalyticsHelper()

synchronized Tracker getTracker(TrackerName trackerId) {
if (!mTrackers.containsKey(trackerId)) {

GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
Tracker t = null;
t= analytics.getTracker(PROPERTY_ID);
mTrackers.put(trackerId, t);
return mTrackers.get(trackerId);

And my analytics xml file in xml directory is as follows:-

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools=""

<!-- The following value should be replaced with correct property id. -->
<string name="ga_trackingId">UA-xxxxxxxx-X</string>

<!--Enable automatic activity tracking-->
<bool name="ga_autoActivityTracking">true</bool>

<!--Enable automatic exception tracking-->
<bool name="ga_reportUncaughtExceptions">true</bool>


Any help will be heart-fully welcomed.
Thanks in advance.

Answer Source

Well the above code given in the Question works well. All you need to do is after setting your code and adding the Jar file Download Google Analytics Jar file to your Lib. just wait for 24 to 48 hours. and it would show all the events and analytic for the App you had registered.

Edited Answer:-

Once You had Created your Google Analytic account and Downloaded the Jar file, Add the Jar file in your lib folder of your Application

Google Analytic Implementation:-

Well For Analytic Part You Just need the analytic.xml file to be included in your values folder which is mentioned in the Question.

Then define private EasyTracker easyTracker = null; in your MainActivity.

And now in your onCreate(Bundle savedInstanceState) method just write the following lines of Code. Well you can also write the following code for any Listners e.g. on any Button Click.

    *For Google Analytics...
    easyTracker = EasyTracker.getInstance(MainActivity.this); // It Tracks your Activity...
            "SomeMoreValue(AuthorName) , "SomeMoreValueAgain(StoryTitle)", null).build()); //This line creates the event for keeping logs and other Analytical stuffs concerned to this Activity of Application...
//In the above example we had Tracked the session for the MainActivity and also Analysed how many time this activity was opened, which Author story and which Story was read.

Now in your onStart() Method, just write the following code, it starts the Tracking and Analytics session for your Activity.


And now in your onStop() Method, just write the following code, it will close or stop the Tracking session for this activity.


Now you are able to Track and Analysis your Application and Activities in It.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download