我对 Android 版 Google Analytics(分析)有疑问。我正在尝试使用电子商务跟踪,但它不起作用。 我发送了一个点击,Eclipse 在 LogCat 中显示了我
Sending hit to service ...
Google Analytics 在“实时”下显示事件(类别、操作、标签),但在“转化”下显示的不是购买的产品。
Product product = new Product()
.setName("myproduct");
tracker
.send(new HitBuilders.EventBuilder()
.setCategory(category)
.setAction(action)
.setLabel(label)
.addProduct(product)
.setProductAction(new ProductAction(ProductAction.ACTION_PURCHASE))
.build());
是的,我已经在数据 View 设置下激活了电子商务
我做错了什么?
最佳答案
下面的代码适合我。
另请注意,转化包括目标和电子商务。实时部分仅显示目标。对于电子商务,您必须等待一段时间,直到事件出现在主转化 -> 电子商务部分(大约 15 分钟或更长时间)。
// Logs a purchase event to Google analytics, for ecommerce tracking.
private void logGooglePurchaseEvent(String transactionId, String productId)
{
// Look up the product's price.
double price = getProductPrice(productId);
// Look up the product's currency.
String currency = getProductPriceCurrency(productId);
// Set up the product.
Product product = new Product()
.setId(productId)
.setName(productId)
.setCategory("iap")
.setPrice(price)
.setQuantity(1);
// Set up the purchase action.
ProductAction productAction =
new ProductAction(ProductAction.ACTION_PURCHASE)
.setTransactionId(transactionId)
.setTransactionAffiliation("Google Play")
.setTransactionRevenue(price);
// Create the builder, which combines the purchase with the product.
HitBuilders.EventBuilder builder =
new HitBuilders.EventBuilder();
builder.setProductAction(productAction).addProduct(product);
builder.setCategory("transaction").setAction("purchase");
// Create the analytics tracker.
GoogleAnalytics analytics = GoogleAnalytics.getInstance(_context);
Tracker tracker = analytics.newTracker(
getGoogleAnalyticsPropertyId());
// Send the event, specifying the currency.
tracker.set("&cu", currency);
tracker.send(builder.build());
}
关于android - Google Analytics 不显示购买但显示事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25586683/