1

I'm trying to implement GA v4 for my app. And I have read docs here, looked here and searched SO for the answer, but all what I found (enableAutoActivityTracking not automatically tracking activities?) did not helped me.

I done some changes to example in the docs and I have this in my Application subclass:

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
}

And in my 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>

So, I have few questions:

  1. Why neither ga_autoActivityTracking nor analytics.enableAutoActivityReports(this) helps? I don't see any dispatching in log. Nothing after Thread[main,5,main]: Connected to service, but all is ok when I sending screens manually.

  2. I don't understand what this constant is for (in examples):

    public static int GENERAL_TRACKER = 0;

  3. Do I need to have to use TrackerName enum and getTracker(TrackerName trackerId) method if I only want to automatically track activities.

Thanks in advance, I really appreciate any help!

4

1 回答 1

0

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

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

但是文档说即使在 DryRun 模式下也必须查看日志记录

于 2014-12-26T19:21:16.800 回答