java 适用于 Android 的 Google Analytics API v4 不发送屏幕视图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25949303/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Google Analytics API v4 for Android Does NOT Send Screen Views
提问by Ertu?rul ?etin
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/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 Modelsin specific time period such as "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);
}
采纳答案by Antwan
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 thisdelete 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
来自谷歌文档的关于这 2 种方法的附加信息
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
回答by pallavi
adding
添加
<application
android:name="mypackagename.MyApplication"
... >
in the manifest file, does the trick.
在清单文件中,可以解决问题。
回答by Beemo
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.
我为此失去了一天。尝试了一切,从文档到 Internet 代码,都没有向我展示整体屏幕视图。终于,今天午夜过后,他们出现了。
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. 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 对谷歌分析没有在实时概览中显示活跃用户的问题有一些很好的见解
回答by Lucas Massuh
@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.
@tony 是对的, HitBuilders.AppViewBuilder
不推荐使用类,但onStart/Stop
如果您不想,则无需实现方法。如GA 的 V4 教程(第 4 节)所述,您可以将 AppViewBuilder 类替换为HitBuilders.ScreenViewBuilder()
,您将在所有平台上获得所需的结果。
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