1

我在安卓应用中成功实现了应用内购买。我只想在谷歌分析中记录购买事件。如果应用程序在前台,我可以通过 PurchaseObserver 记录事件。但是如果应用程序在后台,如何在谷歌分析中记录事件。目前我正在使用 EasyTracking 库来记录事件。

请帮忙。提前致谢。

4

1 回答 1

1

使用新的 v2 Google Analytics Android API 尝试类似的操作

public void onPurchaseCompleted() {
  Transaction myTrans = new Transaction.Builder(
      "0_123456",                                           // (String) Transaction Id, should be unique.
      (long) 2.16 * 1000000)                                // (long) Order total (in micros)
      .setAffiliation("In-App Store")                       // (String) Affiliation
      .setTotalTaxInMicros((long) 0.17 * 1000000)           // (long) Total tax (in micros)
      .setShippingCostInMicros(0)                           // (long) Total shipping cost (in micros)
      .build();

  myTrans.addItem(new Item.Builder(
      "L_789",                                              // (String) Product SKU
      "Level Pack: Space",                                  // (String) Product name
      (long) 1.99 * 1000000,                                // (long) Product price (in micros)
      (long) 1)                                             // (long) Product quantity
      .setProductCategory("Game expansions")                // (String) Product category
      .build());

    Tracker myTracker = EasyTracker.getTracker(); // Get reference to tracker.
    myTracker.trackTransaction(myTrans); // Track the transaction.
}
于 2012-11-25T14:11:23.770 回答