Prerequisites
Before you get started, you’ll need to:
- Grab our latest Unity plugin
- Complete the basic SDK integration, if you haven’t already done so
If you’re setting up PIA and your Unity-built game will end up in the Amazon Appstore or Google Play Store, you’ll also need to add your Amazon Developer Secret key or your app’s public key, respectively, to one of these fields on the game’s App Settings page:
Amazon Appstore
Google Play Store
(You can find your Secret key here. To find your Google Play public key: Sign in to the Google Play Developer Console, go to the Application Details page, click the Services and APIs link, then locate the Licensing and In-App Billing section. You’ll see your public key for in-app billing here.)
Unity PIA Integration
There are several ways to handle the IAP flow in Unity-built games; below are the steps you should use to send the IAP information to Chartboost after successful purchase events:
Unity iOS
1) To be able to call the Chartboost IAP tracking method, you’ll first need to include the class using ChartboostSDK
if you haven’t already done so
2) Send IAP information to the Chartboost SDK:
Chartboost.trackInAppAppleStorePurchaseEvent(receipt, productTitle, productDescription, productPrice, productCurrency, productIdentifier);
Unity Google Play
1) To be able to call the Chartboost IAP tracking method, you’ll first need to include the class using ChartboostSDK
if you haven’t already done so
2) Send IAP information to the Chartboost SDK:
Chartboost.trackInAppGooglePlayPurchaseEvent(title,description,price,currency,productID,purchaseData,purchaseSignature);
Unity Amazon
1) To be able to call the Chartboost IAP tracking method, you’ll first need to include the class using ChartboostSDK
if you haven’t already done so
2) Send IAP information to the Chartboost SDK:
Chartboost.trackInAppAmazonStorePurchaseEvent(title,description,price,currency,productID,userID,purchaseToken);
You can find parameter definitions in the sample project’s Chartboost.cs file (Assets/Chartboost/Scripts/
):
namespace ChartboostSDK { #if UNITY_ANDROID /// <summary> /// Track an In App Purchase Event for Google Play Store. /// Tracks In App Purchases for later use with user segmentation and targeting. /// </summary> /// <param name="title">The localized title of the product.</param> /// <param name="description">The localized description of the product.</param> /// <param name="price">The price of the product.</param> /// <param name="currency">The localized currency of the product.</param> /// <param name="productId">The google play identifier for the product.</param> /// <param name="purchaseData">The purchase data string for the transaction.</param> /// <param name="purchaseSignature">The purchase signature for the transaction.</param> public static void trackInAppGooglePlayPurchaseEvent(string title, string description, string price, string currency, string productID, string purchaseData, string purchaseSignature) { CBExternal.trackInAppGooglePlayPurchaseEvent(title,description,price,currency,productID,purchaseData,purchaseSignature); } /// <summary> /// Track an In App Purchase Event for Amazon Store. /// Tracks In App Purchases for later use with user segmentation and targeting. /// </summary> /// <param name="title">The localized title of the product.</param> /// <param name="description">The localized description of the product.</param> /// <param name="price">The price of the product.</param> /// <param name="currency">The localized currency of the product.</param> /// <param name="productID">The amazon identifier for the product.</param> /// <param name="userID">The user identifier for the transaction.</param> /// <param name="purchaseToken">The purchase token for the transaction.</param> public static void trackInAppAmazonStorePurchaseEvent(string title, string description, string price, string currency, string productID, string userID, string purchaseToken) { CBExternal.trackInAppAmazonStorePurchaseEvent(title,description,price,currency,productID,userID,purchaseToken); } #elif UNITY_IPHONE /// <summary> /// Track an In App Purchase Event for iOS App Store. /// Tracks In App Purchases for later use with user segmentation and targeting. /// </summary> /// <param name="receipt">The transaction receipt used to validate the purchase.</param> /// <param name="productTitle">The localized title of the product.</param> /// <param name="productDescription">The localized description of the product.</param> /// <param name="productPrice">The price of the product.</param> /// <param name="productCurrency">The localized currency of the product.</param> /// <param name="productIdentifier">The IOS identifier for the product.</param> public static void trackInAppAppleStorePurchaseEvent(string receipt, string productTitle, string productDescription, string productPrice, string productCurrency, string productIdentifier) { CBExternal.trackInAppAppleStorePurchaseEvent(receipt, productTitle, productDescription, productPrice, productCurrency, productIdentifier); } #endif }
Testing Your PIA Setup (iOS Games Built with Unity)
After completing the PIA integration, you can enable a sandbox mode to test your work, before submitting your game for App Store approval.
To do this, you’ll need to enable a test mode flag in the Chartboost SDK via an environment variable in Xcode. Here’s how:
1. Open the scheme section at the top-left corner of Xcode and pick Edit Scheme from the drop-down menu:
2. Click Run in the left-side menu and switch to the Arguments tab:
3. Click the + symbol in the Environment Variables section and type CB_TEST_MODE
in the Name field that appears:
4. Double click the space beneath the Value title and enter on
in the field that appears:
After that, click OK, run your project, and make a purchase in development mode.
CB_TEST_MODE
environment variable before launching your game!Last Updated on February 27, 2018