针对Android问题的Google Analytics(分析)增强型电子商务跟踪

我一直在尝试实施增强型电子商务跟踪,但无论我做什么,Google Analytics(分析)中的电子商务查看网页面板都保持为空,即没有数据发送(显然)。 所有其他数据,屏幕和事件跟踪按预期工作。

我正在关注安装Google分析和实施增强型电子商务跟踪的官方指南。 这是我的设置:

在MyApplication类中:

public class MyApplication extends Application { private Tracker mTracker; //.... synchronized public Tracker getDefaultTracker() { if (mTracker == null) { GoogleAnalytics analytics = GoogleAnalytics.getInstance(this); mTracker = analytics.newTracker(R.xml.global_tracker); mTracker.set("&tid", GOOGLE_ANALYTICS_ID_VALUE); } return mTracker; } } 

R.xml.global_tracker:

 <?xml version="1.0" encoding="utf-8"?> <resources> <integer name="ga_sessionTimeout">300</integer> <bool name="ga_autoActivityTracking">false</bool> <string name="ga_sampleFrequency">100.0</string> <bool name="ga_reportUncaughtExceptions">true</bool> <integer name="ga_dispatchPeriod">30</integer> </resources> 

在BaseActivity类中我有trackEcommerce()方法,我使用适当的活动/碎片:

 public void trackEcommerce(){ String screenName = "eCommerce"; String transactionID = "transactionID"; //some randomized value Double transactionRevenue = 0.0; //value of the transaction Tracker t = ((MyApplication) getApplication()).getDefaultTracker(); //send products for (MyEcommerceItem item : myEcommerceItems) { Product product = new Product() .setId(item.getSku()) .setName(item.getTitle()) .setCategory(item.getType()) .setPrice(item.getPrice()) .setQuantity(item.getQuantity()); HitBuilders.ScreenViewBuilder builder = new HitBuilders.ScreenViewBuilder().addProduct(product); t.setScreenName(screenName); t.send(builder.build()); } //send transaction ProductAction productAction = new ProductAction(ProductAction.ACTION_CHECKOUT) .setTransactionId(transactionID) .setTransactionRevenue(transactionRevenue); HitBuilders.ScreenViewBuilder builder = new HitBuilders.ScreenViewBuilder().setProductAction(productAction); t.setScreenName(screenName); t.send(builder.build()); } 

明显的问题,你能看到我做错了什么/我需要改变一些想法吗?

Solutions Collecting From Web of "针对Android问题的Google Analytics(分析)增强型电子商务跟踪"

您应该使用单独的ecommerce_tracker跟踪器,而不是使用全局跟踪器进行电子商务跟踪。 https://developers.google.com/analytics/devguides/collection/android/v4/advanced#multiple-trackers

 public class MyApplication extends Application { private Tracker mDefaultTracker; private Tracker mEcommerceTracker; //.... synchronized public Tracker getDefaultTracker() { if (mDefaultTracker == null) { GoogleAnalytics analytics = GoogleAnalytics.getInstance(this); mDefaultTracker = analytics.newTracker(R.xml.global_tracker); mDefaultTracker.set("&tid", GOOGLE_ANALYTICS_ID_VALUE); } return mDefaultTracker; } synchronized public Tracker getEcommerceTracker() { if (mEcommerceTracker == null) { GoogleAnalytics analytics = GoogleAnalytics.getInstance(this); mEcommerceTracker = analytics.newTracker(R.xml.ecommerce_tracker); } return mDefaultTracker; } } 

R.xml.ecommerce_tracker

 <?xml version="1.0" encoding="utf-8"?> <resources> <integer name="ga_sessionTimeout">60</integer> <!-- The following value should be replaced with correct property id. --> <string name="ga_trackingId">UA-XXXXXX-Y</string> </resources> 

也试着看看什么是日志输出。 以下是如何从GA https://developers.google.com/android/reference/com/google/android/gms/analytics/Logger启用日&#x5FD7;