因此,我尝试在移动应用中实施Google Analytics。
我已将此compile 'com.google.android.gms:play-services:6.5.87'
添加到build.gradle文件中的依赖项。
这是我的app类:
public class app extends Application {
private static final String PROPERTY_ID = "UA-xxxxxxxx-x";
@Override
public void onCreate()
{
super.onCreate();
}
public enum TrackerName {
APP_TRACKER, // Tracker used only in this app.
GLOBAL_TRACKER
}
HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();
synchronized Tracker getTracker(TrackerName trackerId) {
if (!mTrackers.containsKey(trackerId)) {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
analytics.setLocalDispatchPeriod(30);
analytics.setDryRun(false);
analytics.getLogger().setLogLevel(Logger.LogLevel.INFO);
Tracker t = (trackerId == TrackerName.APP_TRACKER) ? analytics.newTracker(PROPERTY_ID)
: analytics.newTracker(R.xml.global_tracker);
if(t != null)
{
t.enableAdvertisingIdCollection(true);
}
mTrackers.put(trackerId, t);
}
return mTrackers.get(trackerId);
}
在我的活动中,我有了这个:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
// Get tracker.
Tracker t = ((app) getApplication()).getTracker(app.TrackerName.APP_TRACKER);
t.setScreenName("StartActivity");
}
@Override
protected void onStart() {
super.onStart();
GoogleAnalytics.getInstance(this).reportActivityStart(this);
}
@Override
protected void onStop() {
super.onStop();
GoogleAnalytics.getInstance(this).reportActivityStop(this);
}
有了这个,当我在手机上测试应用程序时,我的分析页面根本没有显示任何用户。是否需要时间才能显示(我几小时前只在我的分析面板中为应用程序设置了新帐户)?
感谢您的帮助。