According to the Google Analytics eCommerce guide for Android, I need to use the Tracker.sendTransaction
method to track purchases. Three pieces of information needed are the purchase price, the total tax, and the shipping price (all longs). However, the response provided from making in-app purchases provides none of this data.
Am I missing something? Are these pieces of information actually returned? Where can I find them to set them?
You can get information about all your products using the getSkuDetails-method:
ArrayList<String> skuList = new ArrayList<String> ();
skuList.add("premiumUpgrade");
skuList.add("gas");
Bundle querySkus = new Bundle();
querySkus.putStringArrayList(“ITEM_ID_LIST”, skuList);
Bundle skuDetails = mService.getSkuDetails(3, getPackageName(), "inapp", querySkus);
code taken from: http://developer.android.com/google/play/billing/billing_integrate.html#QueryDetails
You know which product the user bought by inspecting the data returned after a purchase:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1001) {
int responseCode = data.getIntExtra("RESPONSE_CODE", 0);
String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
String dataSignature = data.getStringExtra("INAPP_DATA_SIGNATURE");
if (resultCode == RESULT_OK) {
try {
JSONObject jo = new JSONObject(purchaseData);
String sku = jo.getString("productId");
// TODO: query getSkuDetails() and find the matching product
alert("You have bought the " + sku + ". Excellent choice,
adventurer!");
}
catch (JSONException e) {
alert("Failed to parse purchase data.");
e.printStackTrace();
}
}
}
}
code taken from: http://developer.android.com/google/play/billing/billing_integrate.html#Purchase
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With