Reputation: 6928
I implemented inapp purchase successfully in android app. I just want to log the purchase event in google analytics. If the application is in foreground, i can log the event through PurchaseObserver. But If the application in background, how to log the event in google analytics. Currently i am using EasyTracking library to log the events.
Please Help. thanks in advance.
Upvotes: 1
Views: 688
Reputation: 7696
Try something like this with the new 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.
}
Upvotes: 1