Google Analytics API v4 for Android Does NOT Send Screen Views

醉酒当歌 提交于 2019-12-20 12:28:00

问题


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);
    }

回答1:


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




回答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




回答3:


adding

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

in the manifest file, does the trick.




回答4:


@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



来源:https://stackoverflow.com/questions/25949303/google-analytics-api-v4-for-android-does-not-send-screen-views

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!