public class GooglePlayMonetizationEventBuilder extends MonetizationEventBuilder
org.json.JSONObject on the completion of a
purchase using Google's In App Billing API. Since Google does not give you
any product information in the purchase object, you must have a way to access
your store inventory when the purchase is being finalized. In the example
below, we use a org.json.JSONObject that was returned by a
request to Google's In App Billing API for product skus.
Example:
// create a builder that can record purchase events for Google Play IAP
GooglePlayMonetizationEventBuilder builder = GooglePlayMonetizationEventBuilder.create(pinpointManager.getAnalyticsClient());
// build the monetization event with the product id, formatted item price,
// transaction id, and quantity
// product id and formatted item price can be obtained from the JSONObject
// returned by a product sku request to Google's In App Billing API
// transaction id is obtained from the Purchase object that is returned upon the
// completion of a purchase
// Google IAP currently only supports a quantity of 1
Analytics Event purchaseEvent = builder.withProductId(sku).withFormattedItemPrice(price)
.withTransactionId(purchase.getOrderId()).withQuantity(1).build();
// record the monetization event
pinpointManager.getAnalyticsClient().recordEvent(purchaseEvent);| Modifier | Constructor and Description |
|---|---|
protected |
GooglePlayMonetizationEventBuilder(AnalyticsClient analyticsClient)
Construct a GooglePlayMonetizationEventBuilder with the specified
EventClient
|
| Modifier and Type | Method and Description |
|---|---|
static GooglePlayMonetizationEventBuilder |
create(AnalyticsClient analyticsClient)
Create a GooglePlayMonetizationEventBuilder with the specified Event
client
|
protected boolean |
isValid()
Returns true only if the ProductId, Quantity, Currency, Item Price, and
Transaction Id are set
|
GooglePlayMonetizationEventBuilder |
withCurrency(String currency)
Sets the currency of the item purchased.
|
GooglePlayMonetizationEventBuilder |
withFormattedItemPrice(String formattedItemPrice)
Deprecated.
Will be removed. Please set Currency and Item Price. Replaced by
withCurrency(String) and {@link #withItemPrice(Double) |
GooglePlayMonetizationEventBuilder |
withItemPrice(Double itemPrice)
Sets the item price of the item purchased.
|
GooglePlayMonetizationEventBuilder |
withProductId(String productId)
Sets the product identifier field of the item being purchased.
|
GooglePlayMonetizationEventBuilder |
withQuantity(Double quantity)
Sets the quantity of the item purchased.
|
GooglePlayMonetizationEventBuilder |
withTransactionId(String transactionId)
The transaction identifier of the purchase.
|
build, getCurrency, getFormattedItemPrice, getItemPrice, getProductId, getQuantity, getStore, getTransactionId, setCurrency, setFormattedItemPrice, setItemPrice, setProductId, setQuantity, setStore, setTransactionIdprotected GooglePlayMonetizationEventBuilder(AnalyticsClient analyticsClient)
analyticsClient - The EventClient to use when building the eventpublic static GooglePlayMonetizationEventBuilder create(AnalyticsClient analyticsClient)
analyticsClient - The event client to use when creating monetization
eventspublic GooglePlayMonetizationEventBuilder withProductId(String productId)
productId - The product id representing the item being purchased@Deprecated public GooglePlayMonetizationEventBuilder withFormattedItemPrice(String formattedItemPrice)
withCurrency(String) and {@link #withItemPrice(Double)formattedItemPrice - The localized formatted price of the itempublic GooglePlayMonetizationEventBuilder withQuantity(Double quantity)
quantity - Currently, Google Play only supports purchasing 1 item at
a time.public GooglePlayMonetizationEventBuilder withItemPrice(Double itemPrice)
itemPrice - The numerical price of the itempublic GooglePlayMonetizationEventBuilder withCurrency(String currency)
currency - The currency code of the currency used to purchase this
item (i.e. "USD" or "$")public GooglePlayMonetizationEventBuilder withTransactionId(String transactionId)
transactionId - The orderId found in the INAPP_PURCHASE_DATA of a
purchase requestprotected boolean isValid()
isValid in class MonetizationEventBuilderCopyright © 2017. All rights reserved.