我一直在尝试实施增强型电子商务跟踪,但无论我做什么,Google Analytcs网络面板中的电子商务视图都会保持空白,即没有数据发送(显然)。所有其他数据,屏幕和事件跟踪按预期工作。
我正在关注installing google analytics和implementing Enhanced Ecommerce tracking上的官方指南。以下是我的设置:
在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());
}
显而易见的问题是,你能看到我做错了什么/关于我需要改变的一些想法吗?
答案 0 :(得分:1)
您应该使用单独的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