In App Purchase API
ironSource App Analytics provides analysis of the application revenue from in-app purchase. Analysis of the items available to purchase. Identify where the places the users purchase them and where those items are placed within the location that yield the best revenue.
Analyzing the in-app purchase revenue within the application rely on two phases:
- Settings API (Pre-init)
- Purchases API (Post-init)
Settings API (Pre-init)
Use this API, prior to SDK initialization, to update the in-app purchase settings available in your application. Only settings declared prior to initialization are available for purchases updates
import java.util.ArrayList;
// The in-app purchase settings API
IronSourceAnalytics.setIAPSettings(ISAnalyticsPurchasingType purchasingType, @NonNull List<String> values);
Parameters
- ISAnalyticsPurchasingType purchasingType – an enumeration of the required in-app purchase item to update. Available values:
- PURCHASE_ITEMS – The official declared purchase items’ names that users can buy within the application (Such as 500 coins, a bundle of 1000 coins and 100 gems etc.)
- Recommended to set according to the application unique offering IDs
- ITEM_CATEGORIES – The categories / groups of items that can be purchased by users or places category (Promo pop up, Bundle in shop, Non depositors offerings etc.)
- PURCHASE_PLACEMENTS – The places / locations where users can purchase items within the application (Such as Shop, between levels, Holiday promo pop up etc.)
- PURCHASE_ITEMS – The official declared purchase items’ names that users can buy within the application (Such as 500 coins, a bundle of 1000 coins and 100 gems etc.)
- List<String> values – List of String values paired with the required enum. All values shall be alphanumeric, may include spaces or ‘_’ and limited to 20 characters. Limited to 100 items per list (Per PurchasingType)
Example of in-app purchase settings API
import java.util.ArrayList;
// Example of in-app purchase settings prior to sdk initialization
// First, set all unique offering IDs, or items, that available in the application
ArrayList<String> iapOffersIDs = new ArrayList<>();
iapOffersIDs.add("coins_bundle_12");
iapOffersIDs.add("gems_offer_10102020");
iapOffersIDs.add("holiday_special_300_coins");
IronSourceAnalytics.setIAPSettings(ISAnalyticsPurchasingType.PURCHASE_ITEMS, iapOffersIDs);
// Second, update the offerings categories available in the application
ArrayList<String> iapOfferingCategories = new ArrayList<>();
iapOfferingCategories.add("non_depositors");
iapOfferingCategories.add("holiday_promotion");
iapOfferingCategories.add("begginers_pack");
IronSourceAnalytics.setIAPSettings(ISAnalyticsPurchasingType.ITEM_CATEGORIES, iapOfferingCategories);
// Third, update all locations within the app, or placements, where it is possible to perform any in-app purchase
ArrayList<String> iapOfferingLocations = new ArrayList<>();
iapOfferingLocations.add("out_of_coins_popup");
iapOfferingLocations.add("shop_1");
iapOfferingLocations.add("holiday_popup");
iapOfferingLocations.add("between_levels_4_5");
IronSourceAnalytics.setIAPSettings(ISAnalyticsPurchasingType.PURCHASE_PLACEMENTS, iapOfferingLocations);
Purchases API (Post-init)
Use this API, following the SDK initialization, to update the users’ in-app purchases (Using the items, placements & categories that were set in the pre-init phase)
// The in-app purchase updates API
IronSourceAnalytics.updateUserPurchase(@NonNull ISAnalyticsInAppPurchase userPurchase);
Parameters
- ISAnalyticsInAppPurchase userPurchase – The object that represents the purchase event
ISAnalyticsInAppPurchase Object
This object and it’s properties define all the required information regarding a purchasing event
Constructor:
- ISAnalyticsInAppPurchase(@NonNull String purchasedItem) – The item that was purchased by the user. Must be one of the items declared in the setIAPSettings SDK API, in PURCHASE_ITEMS list
Set methods:
- fromCategory(@NonNull String category) – The category of the purchased item. Must be one of the item types declared in the setIAPSettings SDK API, in ITEM_CATEGORIES list
- paid(float amount) – The amount of the money that was used for the purchase
- currency(@NonNull String currency) – Currencies shall be chosen according to ISO 4217 format
- purchasedPlacement(String purchasedPlacement) – Must be one of the placements the developer passed part of setIAPSettings SDK API, in PURCHASE_PLACEMENTS list
Example of in-app purchase update API
// Example of in-app purchase done by the user
ISAnalyticsInAppPurchase coinsBundle123 = new ISAnalyticsInAppPurchase("coins_bundle_123")
.fromCategory("holiday_promotion")
.paid(15.99f)
.purchasedPlacement("out_of_coins_popup")
.currency("USD");
IronSourceAnalytics.updateUserPurchase(coinsBundle123);