12

I've set all things for google analytics api v4 as it mentioned here:
https://developers.google.com/analytics/devguides/collection/android/v4/
and here: http://www.javacodegeeks.com/2014/04/working-with-google-analytics-api-v4-for-android.html


I can see real time data but i could NOT see Screens, Active Users,New Users and Top Device Models in specific time period such as "All Time".

Analytic does not send screen views.


Here is my global_tracker.xml

    <string name="ga_trackingId">UA-XXXXXXXX-Y</string>

    <integer name="ga_sessionTimeout">300</integer>

    <bool name="ga_autoActivityTracking">true</bool>

    <bool name="ga_reportUncaughtExceptions">true</bool>

    <screenName name="com.org.ScreenActivity1">Screen 1</screenName>
    <screenName name="com.org.ScreenActivity2">Screen 2</screenName>


Here is my AndroidManifest.xml

        <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"/>


Here is my Analytics.java

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.
    }

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

    public Analytics() {
        super();
    }

    public synchronized Tracker getTracker(TrackerName trackerId) {

        if (!mTrackers.containsKey(trackerId)) {

            GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);

            if (trackerId == TrackerName.GLOBAL_TRACKER) {
                mTrackers.put(trackerId, analytics.newTracker(R.xml.global_tracker));
            }

        }

        return mTrackers.get(trackerId);
    }


Here is my Activity class:

protected void onCreate(Bundle bundle){
//......................

Tracker tracker = ((Analytics) getApplication()).getTracker(Analytics.TrackerName.GLOBAL_TRACKER);
        tracker.setScreenName("Main Activity");
        tracker.send(new HitBuilders.AppViewBuilder().build());

//......................

}

    @Override
    protected void onStart() {
        super.onStart();
        GoogleAnalytics.getInstance(this).reportActivityStart(this);
    }

    @Override
    protected void onStop() {
        super.onStop();
        GoogleAnalytics.getInstance(this).reportActivityStop(this);
    }
Ertuğrul Çetin
  • 4,779
  • 4
  • 28
  • 61
  • i have setup all the required code as same as u but i couldn't see the active user in the real time overview and in the log cat i got GAV4 no compagin date found did you pass throw this problem? – Antwan Sep 20 '14 at 13:59
  • I did not get such a error. Did you add the latest googleplayservices to gradle? – Ertuğrul Çetin Sep 20 '14 at 14:47
  • yes i added i have every things work now but on google analytics real time review i didnt see the active client – Antwan Sep 20 '14 at 20:13
  • i guess i find the way its all about UA-XXXXXXXX-1 and UA-XXXXXXXX-2 thing beacuse when i switch to UA-XXXXXXXX-1 i can see real-time data after switch to UA-XXXXXXXX-2 only see screen views not real-time i guess we should add both to app_tracker.xml – Ertuğrul Çetin Sep 20 '14 at 20:17
  • but for me ua-xxx-1 and ua-xxx-2 one for all app and one for website data just ua-xxx-3 for android but i will try – Antwan Sep 20 '14 at 20:28
  • i tried but the same :( – Antwan Sep 20 '14 at 20:39
  • mine too :( if you find a way let me know , if i find a way i let you know :) – Ertuğrul Çetin Sep 20 '14 at 21:25
  • for sure i already have a question about this problem if some one could help – Antwan Sep 20 '14 at 21:46
  • I read your question and it seems that analytics working for you (real-time and screen views data) now.what did you do exatcly, could you write step by step what have you done please? – Ertuğrul Çetin Sep 21 '14 at 06:33
  • try to remove tracker.send(new HitBuilders.AppViewBuilder().build()); bcuz the GoogleAnalytics.getInstance(this).reportActivityStart(this); will do it's job – Antwan Sep 21 '14 at 09:49
  • Okay thank you worked for me too :) – Ertuğrul Çetin Sep 21 '14 at 09:52
  • so i wll added as an answer – Antwan Sep 21 '14 at 09:54

4 Answers4

10

The problem according to @stkent answer is that the AppViewBuilder() is deprecated so you can fix your problem by deleteing this line of code that's what you need in your case And to help people that have same problem after following this delete this line of code

 tracker.send(new HitBuilders.AppViewBuilder().build());

and add this instead

  @Override
protected void onStart() {
    super.onStart();
    GoogleAnalytics.getInstance(this).reportActivityStart(this);
}

@Override
protected void onStop() {
    super.onStop();
    GoogleAnalytics.getInstance(this).reportActivityStop(this);
}

in each activity you want to track

additional info from google doc about those 2 method

reportActivityStop
reportActivityStart

using this with auto tracking is a noop so you can disable it

the original answer is for @skent on this post

Community
  • 1
  • 1
Antwan
  • 3,679
  • 7
  • 38
  • 61
2

I lost one day to this. Tried everyting, from documentation to Internet codes, nothing did the job of showing me overall screen views. Finally, after midnight today, they showed up.

I guess, if Google real time data (sending Tracker in onCreate or similar method) is working for you, then just wait a day, that data will be processed somewhere on Google servers and be ready after some time on analytic dashboard.

ps. don't listen to Tony, his problem is not the same as this one. But stkent has some good insights to the problem google analytics doesn't show the active user in Real time overview

Community
  • 1
  • 1
Beemo
  • 405
  • 5
  • 17
  • i was get nothing but after fixing my problem i can see now what neat need to show so i think it could help plz don't talk about something u didn't try – Antwan Sep 21 '14 at 09:48
  • Your english is bad my friend, I don't understand you very well. Your answer is, I guess, correct now. Even if I'm using standard google code with Tracker sending just like you say in that deleted line and it works for me now. In the end, we can all agree that this Google Analytics is full of illogical code :D – Beemo Sep 21 '14 at 12:33
  • 1
    i agree with you now i found many problem when i follow google analytics guide and i think putting some snippet of code is not good for beginner – Antwan Sep 21 '14 at 14:25
  • No idea why it can't just be as simple as: sendAction(String action)... instead of all this crap, if people want advanced features let them read about it. – Oliver Dixon Apr 24 '15 at 10:56
2

adding

<application
android:name="mypackagename.MyApplication"
... >

in the manifest file, does the trick.

pallavi
  • 412
  • 3
  • 13
1

@tony is right, HitBuilders.AppViewBuilder class is deprecated, but there is no need to implement onStart/Stop methods if you don't want to. As stated on GA's V4 tutorial (section 4), you can replace the AppViewBuilder class by HitBuilders.ScreenViewBuilder() and you'll get the desired result in all platforms.

See further details on the class reference API here: https://developer.android.com/reference/com/google/android/gms/analytics/HitBuilders.ScreenViewBuilder.html

Lucas Massuh
  • 211
  • 2
  • 9