Android - Google Analytics v4点击生成但未发送

时间:2015-02-19 00:16:27

标签: java android google-analytics android-studio google-analytics-v4

我现在遇到的似乎是一个常见的问题,虽然我认为我看到它的原因源于其他东西。

02-18 12:00:13.854    3654-3672/com.mobileanalytics_test V/GAV4﹕ Thread[GAThread,5,main]: connecting to Analytics service
02-18 12:00:13.867    3654-3672/com.mobileanalytics_test V/GAV4﹕ Thread[GAThread,5,main]: connect: bindService returned true for Intent { act=com.google.android.gms.analytics.service.START cmp=com.google.android.gms/.analytics.service.AnalyticsService (has extras) }
02-18 12:00:13.872    3654-3672/com.mobileanalytics_test I/GAV4﹕ Thread[GAThread,5,main]: No campaign data found.
02-18 12:00:13.872    3654-3672/com.mobileanalytics_test V/GAV4﹕ Thread[GAThread,5,main]: Initialized GA Thread
02-18 12:00:13.873    3654-3672/com.mobileanalytics_test V/GAV4﹕ Thread[GAThread,5,main]: Loaded clientId
02-18 12:00:13.874    3654-3672/com.mobileanalytics_test V/GAV4﹕ Thread[GAThread,5,main]: putHit called
02-18 12:00:13.874    3654-3672/com.mobileanalytics_test V/GAV4﹕ Thread[GAThread,5,main]: Loaded clientId
02-18 12:00:13.874    3654-3672/com.mobileanalytics_test V/GAV4﹕ Thread[GAThread,5,main]: putHit called
02-18 12:00:13.876    3654-3654/com.mobileanalytics_test V/GAV4﹕ Thread[main,5,main]: service connected, binder: android.os.BinderProxy@<Redacted>
02-18 12:00:13.877    3654-3654/com.mobileanalytics_test V/GAV4﹕ Thread[main,5,main]: bound to service
02-18 12:00:13.878    3654-3654/com.mobileanalytics_test V/GAV4﹕ Thread[main,5,main]: Connected to service
02-18 12:00:13.890    3654-3672/com.mobileanalytics_test V/GAV4﹕ Thread[GAThread,5,main]: Sending hit to service   PATH: <SNIP>
02-18 12:00:13.913    3654-3672/com.mobileanalytics_test V/GAV4﹕ Thread[GAThread,5,main]: Sending hit to service   PATH: <SNIP>
02-18 12:09:23.372    3654-3672/com.mobileanalytics_test V/GAV4﹕ Thread[GAThread,5,main]: Loaded clientId
02-18 12:09:23.372    3654-3672/com.mobileanalytics_test V/GAV4﹕ Thread[GAThread,5,main]: putHit called
02-18 12:09:23.378    3654-3672/com.mobileanalytics_test V/GAV4﹕ Thread[GAThread,5,main]: Sending hit to service   PATH: <SNIP>

这里关注我的部分是,尽管在我的global_tracker.xml文件中每隔30秒配置一次,但我看不到我的调度。下面是所有相关的代码,我已经浏览了它,我找到了每个教程,但我找不到我做错了什么。

global_tracker.xml

 <?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="TypographyDashes">
    <string name="ga_logLevel">verbose</string>
    <int name="ga_dispatchPeriod">30</int>
    <bool name="ga_dryRun">false</bool>
    <string name="com.mobileanalytics_test.MainActivity">Test Activity Reporting</string>
</resources>

app_tracker.xml

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="TypographyDashes">
    <string name="ga_trackingId">UA-XXXXXXXX-Y</string>
    <string name="ga_sampleFrequency">100.0</string>
    <bool name="ga_autoActivityTracking">true</bool>
    <bool name="ga_reportUncaughtExceptions">true</bool>
    <integer name="ga_sessionTimeout">-1</integer>
    <screenName name="com.mobileanalytics_test.MainActivity">Test Activity Reporting</screenName>
</resources>

MyApplicationClass.java

public class MyApplicationClass extends Application {

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

    public enum TrackerName {
        APP_TRACKER,
        GLOBAL_TRACKER
    }

    HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();

    synchronized Tracker getTracker(TrackerName trackerId) {
        if (!mTrackers.containsKey(trackerId)) {

            GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
            //Tracker t = analytics.newTracker(R.xml.app_tracker);
            Tracker t = (trackerId == TrackerName.APP_TRACKER) ? analytics.newTracker(PROPERTY_ID)
            :  analytics.newTracker(R.xml.global_tracker);
            //Tracker t = (trackerId == TrackerName.APP_TRACKER) ? analytics.newTracker(PROPERTY_ID)
            //        : (trackerId == TrackerName.GLOBAL_TRACKER) ? analytics.newTracker(R.xml.global_tracker)
            //       : analytics.newTracker(R.xml.ecommerce_tracker);
            mTrackers.put(trackerId, t);

        }
        return mTrackers.get(trackerId);

    }
}

MainActivity.Java

public class MainActivity extends Activity {

    Tracker tracker;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //GoogleAnalytics googleAnalytics = GoogleAnalytics.getInstance(this);
        //tracker.start("UA-XXXXXXXX-Y");

        //Get a Tracker (should auto-report)
        tracker = ((MyApplicationClass) getApplication()).getTracker(MyApplicationClass.TrackerName.APP_TRACKER);

    }

    @Override
    protected void onStart() {
        super.onStart();
        //Get an Analytics tracker to report app starts and uncaught exceptions etc.
        tracker.send(new HitBuilders.EventBuilder("Test", "Load").build());
        //GoogleAnalytics.getInstance(this).reportActivityStart(this);
    }

    @Override
    protected void onStop() {
        super.onStop();
        //Stop the analytics tracking
        GoogleAnalytics.getInstance(this).reportActivityStop(this);
    }
}

我从昨天开始大致处于这个阶段,所以我正在测试“等待”解决方案。我正在查看实时概述,这是我的理解,我的命中应该在接近实时的时间出现在那里,但我什么也没看到。我的目标是API 21 - Android 5.0.1

欢迎任何提示!

1 个答案:

答案 0 :(得分:-2)

在Google Play设备上运行时,Analytics SDK会尝试连接到Google Play服务提供的Google Analytics服务,并将点击发送到服务。该服务提供更可靠的传送机制,因为它不受应用程序生命周期限制。使用Google Analytics服务时,本地调度间隔无效,应用程序点击会立即发送到服务。从您的日志中可以看出您已成功连接到该服务:

Thread[main,5,main]: service connected, binder: android.os.BinderProxy@...

并成功发送要由服务发送的匹配:

Thread[GAThread,5,main]: Sending hit to service   PATH: <SNIP>

当Analytics服务连接失败时,您将看到一条日志消息,指出该消息将根据本地调度间隔从应用进程调度。如果您的应用在非Google Play设备上运行(例如Amazon Fire手机或没有Google Play服务的模拟器)或Google Play服务当前不可用(例如服务正在更新),就会发生这种情况。