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.

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 vs. Custom Attributes vs Purchase Events in our Best Practices section.

Tracking Purchases & Revenue

To use this feature, add this method call after a successful purchase in your app:

1
2
3
[[Appboy sharedInstance] logPurchase:@"your product ID"
inCurrency:@"USD"
atPrice:[[[NSDecimalNumber alloc] initWithString:@"0.99"] autorelease]];
1
Appboy.sharedInstance().logPurchase("your product ID", inCurrency: "USD", atPrice: NSDecimalNumber(string: "0.99"))
  • Supported currency symbols include: USD, CAD, EUR, GBP, JPY, AUD, CHF, NOK, MXN, NZD, CNY, RUB, TRY, INR, IDR, ILS, SAR, ZAR, AED, SEK, HKD, SPD, DKK, and TWD.
    • Any other provided currency symbol will result in a logged warning and no other action taken by the SDK.
  • The product ID can have a maximum of 255 characters
  • Please note that if the product identifier is empty, the purchase will not be logged to Braze.

Adding Properties

You can add metadata about purchases by passing an NSDictionary populated with NSNumber, NSString, or NSDate values.

Please see the iOS Class Documentation for additional details.

Adding Quantity

You can add a quantity to your purchases if customers make the same purchase multiple times in a single checkout. You can accomplish this by passing in a NSUInteger for the quantity.

  • A quantity input must be in the range of [0, 100] for the SDK to log a purchase.
  • Methods without a quantity input will have a default quantity value of 1.
  • Methods with a quantity input have no default value and must receive a quantity input for the SDK to log a purchase.

Please see the iOS Class Documentation for additional details.

If you pass in a value of 10 USD, and a quantity of 3 then that will log to the user’s profile as 3 purchases of 10 dollars for a total of 30 dollars.

1
2
3
4
[[Appboy sharedInstance] logPurchase:@"your product ID"
inCurrency:@"USD"
atPrice:[[[NSDecimalNumber alloc] initWithString:@"0.99"] autorelease]
withProperties:@{@"key1":"value1"}];
1
Appboy.sharedInstance().logPurchase("your product ID", inCurrency: "USD", atPrice: NSDecimalNumber(string: "0.99"), withProperties: ["key1":"value1"])

See the Technical Documentation for more information.

Reserved Keys

The following keys are RESERVED and CANNOT be used as Purchase Properties:

  • time
  • product_id
  • quantity
  • event_name
  • price
  • currency

Implementation Example

logPurchase is utilized within the EventsViewController.m file in the Stopwatch sample application.

REST API

You can also use our REST API to record purchases. Refer to the user API documentation for details.

WAS THIS PAGE HELPFUL?
New Stuff!