Advertise

Last Updated on

July 15, 2022

Unity

Prerequisites

Before you get started, you'll need to:

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:

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:

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:

You can find parameter definitions in the sample project's Chartboost.cs file (Assets/Chartboost/Scripts/):


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.

Be sure to remove the CB_TEST_MODE environment variable before launching your game!