Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do I get the item price, total tax, and shipping cost when tracking purchases on Android?

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?

like image 546
Matt Huggins Avatar asked Jul 09 '13 00:07

Matt Huggins


1 Answers

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

like image 181
TomTasche Avatar answered Oct 26 '22 06:10

TomTasche