Best And Simple Example Of How to integrate Google Analytic to Android App

Best And Simple Example Of How to integrate  Google Analytic to  Android App


GoogleAnalyticsApp


public class GoogleAnalyticsApp extends Application {

// change the following line
private static final String PROPERTY_ID = "U----------1";

public static int GENERAL_TRACKER = 0;

public enum TrackerName {
APP_TRACKER, GLOBAL_TRACKER, ECOMMERCE_TRACKER,
}

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

public GoogleAnalyticsApp() {
super();
}

public synchronized Tracker getTracker(TrackerName appTracker) {
if (!mTrackers.containsKey(appTracker)) {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
Tracker t = (appTracker == TrackerName.APP_TRACKER) ? analytics.newTracker(PROPERTY_ID) : (appTracker == TrackerName.GLOBAL_TRACKER) ? analytics.newTracker(R.xml.global_tracker) : analytics.newTracker(R.xml.ecommerce_tracker);
mTrackers.put(appTracker, t);
}
return mTrackers.get(appTracker);
}
}

In your Actvity:

In Oncreate:
Tracker t = ((GoogleAnalyticsApp) getApplication()).getTracker(TrackerName.APP_TRACKER);
t.setScreenName("Home");
t.send(new HitBuilders.AppViewBuilder().build());

And This Two method

protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
GoogleAnalytics.getInstance(GoogleAnalyticsExample.this).reportActivityStart(this);
}


@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
GoogleAnalytics.getInstance(GoogleAnalyticsExample.this).reportActivityStop(this);
}

Download this File And make xml folder in res Folder in project

http://downloads.ziddu.com/download/25133967/xml.rar.html


In Androdimanifest.xml File


 <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />


 <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <meta-data
        android:name="com.google.android.gms.analytics.globalConfigResource"
        android:resource="@xml/global_tracker" />

and main thing add in application name


1)
  <application
        android:allowBackup="true"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" android:name="GoogleAnalyticsApp">

2)In mainfest file click on application and add application name



Download Whole code below


Best And Simple Example Of How to integrate Google Analytic to Android App Best And Simple Example Of How to integrate  Google Analytic to  Android App Reviewed by Anonymous on December 16, 2015 Rating: 5

No comments:

Java Ternary Operator

Java Ternary Operator Java ternary operator is the only conditional operator that takes three operands. Java ternary operator is a one l...

Powered by Blogger.