Android的谷歌分析API v4不发送屏幕视图

时间:2022-07-31 15:16:18

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

我已经为谷歌分析api v4设置了所有的东西,如这里所提到的:https://developers.google.com/analytics/devguides/collection/android/v4/,这里:http://www.javacodegeeks.com/2014/04/workwith-googleanalytics-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".

我可以看到实时数据,但在特定的时间段,比如“All time”,我看不到屏幕、活跃用户、新用户和*设备模型。

Analytic does not send screen views.

分析不发送屏幕视图。


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:

这是我的活动课:

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

4 个解决方案

#1


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

根据@stkent的回答,问题是不赞成使用AppViewBuilder(),因此您可以通过删除这一行代码来解决问题,这是您在本例中需要的代码,并帮助在删除这一行代码后遇到同样问题的人

 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

关于这两种方法,谷歌doc提供更多信息

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在这篇文章。

#2


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.

我猜,如果谷歌实时数据(在onCreate中发送跟踪器或类似方法)对您有效,那么只需等待一天,该数据将在谷歌服务器上的某个地方处理,并在分析仪表板上等待一段时间后准备好。

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

#3


2  

adding

添加

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

in the manifest file, does the trick.

在manifest文件中,这是诀窍。

#4


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.

HitBuilders @tony是正确的。不赞成使用AppViewBuilder类,但是如果您不想实现onStart/Stop方法,则不需要实现它们。正如GA的V4教程(第4节)中所述,您可以用hitbuild . 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

#1


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

根据@stkent的回答,问题是不赞成使用AppViewBuilder(),因此您可以通过删除这一行代码来解决问题,这是您在本例中需要的代码,并帮助在删除这一行代码后遇到同样问题的人

 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

关于这两种方法,谷歌doc提供更多信息

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在这篇文章。

#2


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.

我猜,如果谷歌实时数据(在onCreate中发送跟踪器或类似方法)对您有效,那么只需等待一天,该数据将在谷歌服务器上的某个地方处理,并在分析仪表板上等待一段时间后准备好。

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

#3


2  

adding

添加

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

in the manifest file, does the trick.

在manifest文件中,这是诀窍。

#4


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.

HitBuilders @tony是正确的。不赞成使用AppViewBuilder类,但是如果您不想实现onStart/Stop方法,则不需要实现它们。正如GA的V4教程(第4节)中所述,您可以用hitbuild . 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