Logging purchases
Record in-app purchases so that you can track your revenue over time and across revenue sources, as well as segment your users by their lifetime value. This reference article shows how to track in-app purchases and revenue and assign purchase properties in your Android or FireOS application.
Braze supports purchases in multiple currencies. Purchases that you report in a currency other than USD will be shown in the dashboard in USD based on the exchange rate at the date they were reported.
Before implementation, be sure to review examples of the segmentation options afforded by custom events, custom attributes, and purchase events in our analytics overview.
Tracking purchases and revenue
To use this feature, call logPurchase()
after a successful purchase in your app. If the product Identifier is empty, the purchase will not be logged to Braze.
1
2
3
4
5
6
Braze.getInstance(context).logPurchase(
String productId,
String currencyCode,
BigDecimal price,
int quantity
);
1
2
3
4
5
6
Braze.getInstance(context).logPurchase(
productId: String,
currencyCode: String,
price: BigDecimal,
quantity: Int
)
If you pass in a value of 10 USD
and a quantity of 3
, that will log to the user’s profile as three purchases of 10 dollars for a total of 30 dollars. Quantities must be less than or equal to 100. Values of purchases can be negative.
Adding properties
You can add metadata about purchases by either passing an event property array or a Braze Properties object with your purchase information.
Braze properties object formatting
Properties are defined as key-value pairs. Keys are String
objects, and values can be String
, int
, float
, boolean
, or Date
objects.
1
2
3
BrazeProperties purchaseProperties = new BrazeProperties();
purchaseProperties.addProperty("key", "value");
Braze.getInstance(context).logPurchase(..., purchaseProperties);
1
2
3
val purchaseProperties = BrazeProperties()
purchaseProperties.addProperty("key", "value")
Braze.getInstance(context).logPurchase(..., purchaseProperties)
Refer to our KDoc for more information.
Log purchases at the order level
If you want to log purchases at the order level instead of the product level, you can use order name or order category as the product_id
. Refer to our purchase object specification to learn more.
Reserved keys
The following keys are reserved and cannot be used as purchase properties:
time
product_id
quantity
event_name
price
currency
REST API
You can also use our REST API to record purchases. Refer to the User API documentation for details.