2014-08-30 80 views
2

我的Android版Google Analytics(分析)出現問題。我正嘗試使用電子商務跟蹤,但不起作用。 我送的命中和Eclipse顯示我在logcat的Google Analytics(分析)不顯示購買,但顯示活動

Sending hit to service ... 

谷歌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()); 

是的,我已經在數據視圖設置

我做錯了啓動電子商務?

回答

1

下面的代碼適用於我。

另請注意,轉化包括目標和電子商務。實時部分只顯示目標。對於電子商務,您必須等待一段時間,直到事件出現在主要的「轉化」 - >「電子商務」部分(大約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()); 
} 
+0

我想需要注意的主要事情是 'ProductAction productAction =新ProductAction(ProductAction.ACTION_PUR​​CHASE) .setTransactionId(transactionId的) .setTransactionAffiliation( 「谷歌播放」) .setTransactionRevenue(價格);' – 2016-10-07 13:23:31

相關問題