Monetize

Last Updated on

August 12, 2022

Unity (SDK Integration)

Please note that starting from Chartboost SDK 9.0.0, our Unity plugin is not supported anymore. Rather, we recommend to use a Mediation solution that supports Unity and includes Chartboost, like Mediation.

Before you begin:

Adding the SDK to your games is quick and easy – you just need a few ingredients:

  • A Chartboost account
  • An app in your dashboard
  • The latest SDK
  • Chartboost supports Unity 2017 and above.
  • Please note that Chartboost supports Android 5 and iOS 9.0, so make sure to set the minimum OS versions of your Unity project accordingly.
  • Also, to ensure compatibility with Android 6.0 Marshmallow devices and features, you should make sure that you’re building, compiling, and targeting against the latest Google Android SDKs (at least API level 23). (However, “minimum” SDK can still target down to API Level 16.)

The Chartboost initialization call must be made during hard and soft bootups within the first few seconds of your app launching, regardless of any other actions or user interaction within your app.

Publishers should call the Chartboost.addDataUseConsent API from the Chartboost SDK and pass in the appropriate value. Publishers are required as part of Terms of Service to obtain the consent from their users before Chartboost will process any personal data and pass it to the Chartboost SDK via the above method. This method should be called as early in the app initialization as possible, or before startWithAppId.

Learn more about privacy methods here and Behavioral Targeting here.

Import the Chartboost Unity package into your project.

If you’re building for iOS, you can skip the Plugins/Android subdirectory; if you’re building for Android, you can skip the Plugins/iOS subdirectory. The files will be organized into a few different directories:

  • /Assets/Chartboost/Editor: Chartboost C# code for Unity Editor integration and the Postprocessbuildscript
  • /Assets/Chartboost/Resources: This folder contains the ChartboostSettings file, which contains the AppId and AppSignature for your iOS and Android apps
  • /Assets/Chartboost/Scripts: C# code for Chartboost use. All our public facing functions are present in Chartboost.cs, in this folder.
  • /Assets/ChartboostExample: An example scene that shows how to use the Chartboost SDK
  • /Assets/Plugins/iOS: Chartboost Objective-C code that helps to integrate it within Unity
  • /Assets/Plugins/Android: Chartboost Android library files

Want to jump right in? Take a look at the files in the ChartboostExample folder. Be sure to watch the log when testing the demo scenes, since some of the buttons will not have obvious effects.

Android: For complex integrations that replace the Android Manifest included in our plugin, any activities that show Chartboost ads must have the value android:hardwareAccelerated="true" in their activity entry on the Android Manifest, or video might not display properly.

If you’re publishing your game in the Google Play Store, link the Google Play Services library with your Unity project.

  • Go to Chartboost > Edit Settings and click Set Up Android SDK.
  • You should use the “Play Services Resolver for Unity” plugin provided by Google to import the Google Play Services Library, which is required for integrating the Chartboost SDK with Android games.
  • Download the latest “Play Services Resolver” plugin here. For example, you can find “1.2.129.0” in this link.
  • Import the “Play Services Resolver” plugin to your Unity project.
  • Right-Click on your project’s “Assets->Plugin->Android” folder and select “Player Services Resolver ->Android Resolver ->Resolve
  • This also requires the Google Play Services library to be installed via the Android SDK Manager. See the Google Developers website for more information.

Add your app ID and app signature.

Remove fillers such as CB_AMAZON_APP_ID and CB_AMAZON_APP_SIGNATURE from the unused store fields or Unity will give you the following error:

Chartboost App ID is a unique App identifier in our systems, therefore it is required to use a different Chartboost App ID per each app.

Drag and drop the Chartboost prefab found at /Assets/Chartboost/Chartboost into your Unity scene in the Scene view.

  • This prefab automatically handles basic SDK behavior like initialization using the app ID and app signature.
  • Tip: Drag the prefab into a scene that only runs once (such as a startup scene) for optimal performance.

To show an interstitial:

  • Include a using ChartboostSDK; reference at the top of each Unity .cs script that will call Chartboost methods.
  • Call the Chartboost class’ public functions present in the /Assets/Chartboost/Scripts/Chartboost.cs file. Check out ChartboostExample.cs in the sample project.
  • To show an ad, you can now call:

We strongly recommend that you cache your interstitials before showing them. Learn more about caching

Prefetched videos (in total) only take up 30-50MB, even when you are using mediation.

Publishers should call the Chartboost.addDataUseConsent API from the Chartboost SDK and pass in the appropriate value. Publishers are required as part of Terms of Service to obtain the consent from their users before Chartboost will process any personal data and pass it to the Chartboost SDK via the above method. This method should be called as early in the app initialization as possible, or before startWithAppId.

If you’re building to iOS devices:

  • The first time you build your project, you should do a Build (not Build & Run) so everything is set up properly.
  • Once the build finishes, open the Xcode project that is created and make sure the StoreKit, Security and CoreData frameworks are linked in the Build Phases settings tab for your target.
  • Add all the required SKAdNetwork IDs to the project’s Info.plist file, as indicated in our integration guide.

Beware of inadvertently disconnecting StoreKit.framework (for example, by disabling in-app purchases) after Unity creates your Xcode project. The Chartboost SDK requires this framework to perform properly.

If you’re building to Android devices:

  • To build your project, do so directly to an APK file or export to an Android Project if you would like to make further modifications in Java.
  • If your app supports multiple orientations, adjust the configChanges settings in your <activity> tag to include these:

Our latest SDK has fixed a compatibility issue with Google Play Services Rev.30. If you have already upgraded to Rev.31, please make sure your Google Repository is also up to date.

w00t! You just integrated the Chartboost SDK into your app!

Now you can start a campaign

More SDK features

  • Chartboost Video: Monetize or acquire users with rewarded or interstitial video ads.
  • Caching: Speed up load times for interstitials, video, and MoreApps pages
  • Named Locations: Fine-tune campaign targeting and interstitial frequency by location. (Note that Named Locations are mandatory as of SDK 5.0.)
  • Delegate Methods: Further tailor Chartboost behavior in your app
  • SDK Configuration Methods: Access Chartboost SDK functionality and settings.

You might also like…

Last Updated on July 8, 2022