Post-Install Analytics Unity
Before You Begin
Before you get started, you'll need to:
- Grab our latest Unity plugin.
- Complete the SDK integration.
Obtain Your Secret Key or Public Key
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
To find your Amazon Appstore's secret key,
- Sign in to the Amazon Developer Console.
- You can find your Secret key here.
Google Play Store
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
- 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
-
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 -
Send IAP information to the Chartboost SDK:
Chartboost.trackInAppAppleStorePurchaseEvent(receipt, productTitle, productDescription, productPrice, productCurrency, productIdentifier);
Unity Google Play
-
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 -
Send IAP information to the Chartboost SDK:
Chartboost.trackInAppGooglePlayPurchaseEvent(title,description,price,currency,productID,purchaseData,purchaseSignature);
Unity Amazon
-
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 -
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
///
/// Track an In App Purchase Event for Google Play Store.
/// Tracks In App Purchases for later use with user segmentation and targeting.
///
/// The localized title of the product.
/// The localized description of the product.
/// The price of the product.
/// The localized currency of the product.
/// The google play identifier for the product.
/// The purchase data string for the transaction.
/// The purchase signature for the transaction.
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);
}
///
/// Track an In App Purchase Event for Amazon Store.
/// Tracks In App Purchases for later use with user segmentation and targeting.
///
/// The localized title of the product.
/// The localized description of the product.
/// The price of the product.
/// The localized currency of the product.
/// The amazon identifier for the product.
/// The user identifier for the transaction.
/// The purchase token for the transaction.
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
///
/// Track an In App Purchase Event for iOS App Store.
/// Tracks In App Purchases for later use with user segmentation and targeting.
///
/// The transaction receipt used to validate the purchase.
/// The localized title of the product.
/// The localized description of the product.
/// The price of the product.
/// The localized currency of the product.
/// The IOS identifier for the product.
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:
- Open the scheme section at the top-left corner of Xcode and pick Edit Scheme from the drop-down menu:
- Click Run in the left-side menu and switch to the Arguments tab:
- Click the + symbol in the Environment Variables section and type
CB_TEST_MODE
in the Name field that appears:
- 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.
Be sure to remove the CB_TEST_MODE
environment variable before launching your game!
Updated 2 days ago