Google Analytics for Android v4自动屏幕跟踪功能无效

时间:2014-07-04 09:26:51

标签: android google-analytics-v4

我正在尝试为我的应用实施GA v4。 我阅读了文档here,看了here并搜索了SO的答案,但我找到的所有内容(enableAutoActivityTracking not automatically tracking activities?)都没有帮助我。

我对文档中的示例做了一些更改,我在应用程序子类中有这个:

package com.example;

import ...

public class AppSubclass extends Application {

    private static final String TAG = "AppSubclass";

    @Override
    public void onCreate() {
        super.onCreate();
        initIrrImageLoader();

        ...

        initGoogleAnalytics();
    }

    private void initGoogleAnalytics() {
        GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);

        // True to prevent sending reports to server (for debugging)
        analytics.setDryRun(true);

        analytics.setLocalDispatchPeriod(10); // In seconds, default 1800

        analytics.getLogger().setLogLevel(Logger.LogLevel.VERBOSE);

        // Enable automatic activity tracking
        analytics.enableAutoActivityReports(this);
    }

    //region GOOGLE ANALYTICS TRACKERS INIT

    private static final String PROPERTY_ID = "UA-XXXXXXXX-1";

    public static int GENERAL_TRACKER = 0;

    // We will use only one tracker for now. You can use multiple,
    // see https://developers.google.com/analytics/devguides/collection/android/v4/
    Tracker mAppTracker;

    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.
        ECOMMERCE_TRACKER, // Tracker used by all ecommerce transactions from a company.
    }

    public synchronized Tracker getTracker(TrackerName trackerId) {
        if (mAppTracker == null) {
            GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
            mAppTracker = analytics.newTracker(R.xml.app_tracker);
        }
        return mAppTracker;
    }

    //endregion
}

在我的 res / xml / app_tracker.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <!--  App property id. -->
    <string name="ga_trackingId">UA-XXXXXXXX-1</string>

    <!-- Enable automatic Activity measurement -->
    <bool name="ga_autoActivityTracking">true</bool>

    <!-- The screen names that will appear in reports -->
    <string name="com.example.SomeActivity">
        SomeActivity
    </string>

    <!-- Timeout after stopping till new session start -->
    <integer name="ga_sessionTimeout">600</integer>

    <!-- Report uncaught exceptions -->
    <bool name="ga_reportUncaughtExceptions">true</bool>

</resources>

所以,我几乎没有问题:

  1. 为什么ga_autoActivityTracking和analytics.enableAutoActivityReports(this)都没有帮助?我没有在日志中看到任何调度。 Thread[main,5,main]: Connected to service之后没有任何内容,但是当我手动发送屏幕时一切正常。

  2. 我不明白这个常量是什么(在例子中):

    public static int GENERAL_TRACKER = 0;

  3. 如果我只想自动跟踪活动,是否需要使用TrackerName枚举和getTracker(TrackerName trackerId)方法。

  4. 提前致谢,我真的很感激任何帮助!

1 个答案:

答案 0 :(得分:0)

我可以尝试帮助您解决第一个问题,这是您的代码:

// True to prevent sending reports to server (for debugging)
analytics.setDryRun(true);

但是文档说你必须在DryRun模式下看到日志记录