Its my First time trying to integrate "Google Analytic" to y Android App. I followed this Tutorial
https://developers.google.com/analytics/devguides/collection/android/v4/
But its not working. Whats the Problem. May be I haven't written the Complete Code. May Be I am missing something. I don't know the exact Procedure.
What I did is,
1st, Added Permission in My Manifest File as follows
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
2nd, added dependency in project's gradle file
In Top Level
classpath com.google.gms:google-services:1.3.0-beta1
In Project Level
apply plugin: 'com.google.gms.google-services'
compile 'com.google.android.gms:play-services-analytics:7.3.0'
3rd, I Created and Downloaded a "Configuration File" as mentioned in the above Link, and placed that file in "app" folder in my Project Directory
4th, I created a class named "AnalyticsApplication" which extends "Application" with the following code
public class AnalyticsApplication extends Application{ private Tracker mTracker; synchronized public Tracker getDefaultTracker() { if (mTracker == null) { GoogleAnalytics analytics = GoogleAnalytics.getInstance(this); // To enable debug logging use: adb shell setprop log.tag.GAv4 DEBUG mTracker = analytics.newTracker(R.xml.global_tracker); } return mTracker; } }
5th, in onCreate method of any one Activity which I want to Track, I wrote the following Code
AnalyticsApplication application = (AnalyticsApplication) getApplication();
mTracker = application.getDefaultTracker();
Then, in onResume method of that Activity, I wrote the following Code
Log.i(LOG_TKT,"Setting screen name: " + "MainActivity Screen");
mTracker.setScreenName("Image~" + "MainActivity Screen");
mTracker.send(new HitBuilders.ScreenViewBuilder().build());
mTracker.send(new HitBuilders.EventBuilder()
.setCategory("Action")
.setAction("Share")
.build());
That's it. Please Help where I went wrong. OR What is the Correct Method of doing it ?