0

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 ?

soumya
  • 3,801
  • 9
  • 35
  • 69
Avtar Singh
  • 261
  • 8
  • 14
  • how do you know its not working? did you check the real-time reports on the Google Analytics website? When did you create the Google Analytics application account? – Linda Lawton - DaImTo Sep 07 '15 at 09:52
  • Hey @DaImTo I Create my Google Analytics account, because of this, I was able to create and download the Configuration File as mentioned in the Link. I am checking the Google Analytic Real Time Page, but its showing 0 – Avtar Singh Sep 07 '15 at 09:58
  • How long ago did you create the Google Analytics account? It takes 48 - 72 hours for it to start showing data. – Linda Lawton - DaImTo Sep 07 '15 at 09:59
  • @DaImTo okie, But it should show the Real time instantly. I mean if I open my App, I should be able to see 1 Device live in my Real Time Google Analytic Page. I am not able to see this Real Time stats. And Secondly I think its updating after 48 hours but when I see the country wise, its showing me wrong countries, and my country is 0 – Avtar Singh Sep 07 '15 at 10:04
  • Actually @DaImTo I dont know exactly how to check this whole process, that, whether its correctly monitoring my app or not ? whether its working or not ? – Avtar Singh Sep 07 '15 at 10:06
  • If its a brand new created Google analytics account you will need to wait a few days for it to start showing data. If your code is correct it should show data in the real-time reports instantly. data will appear in the standard reports 24 hours after that. – Linda Lawton - DaImTo Sep 07 '15 at 10:15
  • @DaImTo yes you r right. This is the problem. I want to know whether my written code is correct or not ? Could you please give my any link or tutorial which you have tested as 100% working ? – Avtar Singh Sep 07 '15 at 10:26
  • sorry I am not an android developer if you followed Googles tutorial it "should" work. That tutorial is very reliable to my knowledge it works. Wait the few days and wait for an android developer to double check your code. But 90% of the time the issue is that the account is to new to display data. If you are lucky it will show up tomorrow. – Linda Lawton - DaImTo Sep 07 '15 at 10:35
  • Have you added android:name=".AnalyticsApplication" into your application tag in the manifest? – JesusS Sep 07 '15 at 10:51
  • @JesusS Yes `android:name=".AnalyticsApplication"` inside tag in Manifest File – Avtar Singh Sep 07 '15 at 11:10

0 Answers0