简体   繁体   English

适用于Android的Google AnalyticsAPI v4不会发送屏幕视图

[英]Google Analytics API v4 for Android Does NOT Send Screen Views

I've set all things for google analytics api v4 as it mentioned here: 我为google analytics api v4设置了所有内容,如下所述:
https://developers.google.com/analytics/devguides/collection/android/v4/ 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 在这里: 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. Analytic不发送屏幕视图。


Here is my global_tracker.xml 这是我的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 这是我的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 这是我的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 : 这是我的Activity类

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

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 根据@stkent回答的问题是, AppViewBuilder()已被弃用,因此您可以用delete一个这行代码,这就是你需要在你的情况下,为了帮助有同样问题的人以下后解决您的问题, 这个删除此行代码

 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 使用这个与自动跟踪是一个noop所以你可以禁用它

the original answer is for @skent on this post 这个帖子的原始答案是@skent

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. 我想,如果Google实时数据(以onCreate或类似方式发送Tracker)对您有用,那么只需等待一天,该数据将在Google服务器上的某个位置进行处理,并在分析仪表板上完成一段时间后就绪。

ps. 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 但是stkent对问题有一些很好的见解, 谷歌分析没有在实时概述中显示活跃用户

adding 加入

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

in the manifest file, does the trick. 在清单文件中,诀窍。

@tony is right, HitBuilders.AppViewBuilder class is deprecated, but there is no need to implement onStart/Stop methods if you don't want to. @tony是对的,不推荐使用HitBuilders.AppViewBuilder类,但如果你不想这样做,则无需实现onStart/Stop方法。 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. 正如GA的V4教程 (第4节)所述,您可以通过HitBuilders.ScreenViewBuilder()替换AppViewBuilder类,您将在所有平台上获得所需的结果。

See further details on the class reference API here: https://developer.android.com/reference/com/google/android/gms/analytics/HitBuilders.ScreenViewBuilder.html 请在此处查看有关课程参考API的更多详细信息: https//developer.android.com/reference/com/google/android/gms/analytics/HitBuilders.ScreenViewBuilder.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM