Snake Snake - 3 months ago 32
Android Question

Using google analytics with eclipse

I am trying to use google analytics with Eclipse. I check google page

https://developers.google.com/analytics/devguides/collection/android/v4/

And their instructions are for Android studio. How can I integrate the analytics in eclipse ? I searched for how to integrate this JSON file and I can't find any hints

please help

Answer

This is the only way, how to achieve this in android development for Google analytics no matter whether it is for Android Studio or Eclipse IDE.

You can simply follow these steps in Eclipse project:

Step 1 : Take INTERNET and ACCESS_NETWORK_STATE permissions.

Step 2 : Add "Google Play service" library project with your project.

Step 3 : Create an Application Class in your project, and write this code on their

private Tracker mTracker;
synchronized public Tracker getDefaultTracker() {
    if (mTracker == null) {
       GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
       mTracker = analytics.newTracker(R.xml.global_tracker);
    }
    return mTracker;
}

Step 4 : Add this code on your onCreate method which you want to track

private Tracker mTracker;
AnalyticsApplication application = (AnalyticsApplication) getApplication();
mTracker = application.getDefaultTracker();

Step 5 : Write this in onResume :

mTracker.setScreenName("Page1" + name);
mTracker.send(new HitBuilders.ScreenViewBuilder().build());

Step 6 : Add configuration file in your project.

Now run the app and check Google analytics in browser.

Comments