Unity - Adapty SDK installation & configuration
Learn how to install and configure Adapty SDK and AdaptyUI SDK for Unity, essential for seamless integration of Adapty into your mobile app
Adapty comprises two crucial SDKs for seamless integration into your mobile app:
- General AdaptySDK: This is a fundamental, mandatory SDK necessary for the proper functioning of Adapty within your app.
- AdaptyUI SDK: This optional SDK becomes necessary if you intend to use the Adapty Paywall builder. The Paywall builder serves as a convenient, user-friendly tool tailored for a no-code approach. It empowers you with the ability to effortlessly construct a subscription purchase page, referred to as a Paywall in Adapty. This approach ensures you get the paywalls directly in your iOS or Android apps as native layout pages.
The Adapty Paywall builder is created to set the core conversion-driving elements of paywalls with several clicks in the dashboard without spending time on minor design amendments and technical settings. It helps also to edit your paywall native layout on the fly by changing it visually in the Adapty web interface.
Please consult the compatibility table below to choose the correct pair of Adapty SDK and AdaptyUI SDK.
Adapty SDK version | AdaptyUI version |
---|---|
2.7.x | 2.0.2 |
2.8.0 and later | not supported |
Go through release checklist before releasing your app
Before releasing your application, make sure to carefully review the Release Checklist thoroughly. This checklist ensures that you've completed all necessary steps and provides criteria for evaluating the success of your integration.
Install Adapty SDKs
To install the Adapty SDKs:
-
Download the
adapty-unity-plugin-*.unitypackage
from GitHub and import it into your project. -
Download the
adapty-ui-unity-plugin-*.unitypackage
from GitHub and import it into your project. -
Download and import the External Dependency Manager plugin.
-
The SDK uses the "External Dependency Manager" plugin to handle iOS Cocoapods dependencies and Android gradle dependencies. After the installation, you may need to invoke the dependency manager:
Assets -> External Dependency Manager -> Android Resolver -> Force Resolve
and
Assets -> External Dependency Manager -> iOS Resolver -> Install Cocoapods
-
When building your Unity project for iOS, you would get
Unity-iPhone.xcworkspace
file, which you have to open instead ofUnity-iPhone.xcodeproj
, otherwise, Cocoapods dependencies won't be used.
Configure Adapty SDKs
To configure the Adapty SDKs for Unity, start by initializing the Adapty Unity Plugin and then using it as described in the guidance below. Additionally, ensure to set up your logging system to receive errors and other important information from Adapty.
Initiate Adapty Unity Plugin on iOS
The Adapty Unity Plugin on iOS is initialized automatically. To make it work properly:
- Manually create the
Adapty-Info.plist
file and add it to the/Assets
folder of your Unity project. It will be automatically copied to the Xcode project during the build phase. Below is an example of how this file should be structured:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AdaptyPublicSdkKey</key>
<string>insert_here_your_Adapty_public_key#</string>
<key>AdaptyObserverMode</key>
<false/>
</dict>
</plist>
Parameters:
Parameter | Presence | Description |
---|---|---|
AdaptyPublicSdkKey | required | The key you can find in the Public SDK key field of your app settings in Adapty: App settings-> General tab -> API keys subsection |
AdaptyObserverMode | optional | A boolean value controlling Observer mode. Turn it on if you handle purchases and subscription status yourself and use Adapty for sending subscription events and analytics. The default value is false .🚧 When running in Observer mode, Adapty SDK won't close any transactions, so make sure you're handling it. |
idfaCollectionDisabled | optional | A boolean parameter, that allows you to disable IDFA collection for your app. The default value is false .For more details, refer to the Analytics integration section. |
Initiate Adapty Unity Plugin on Android
The Adapty Unity Plugin on Android is automatically initialized. To ensure it works properly:
- Add
<meta-data
section with "AdaptyPublicSdkKey" as a direct child of the<application
section to your project's AndroidManifest.xml file. If you don't have one, it can be easily created in Project Settings -> Player -> Settings for Android -> Publishing settings -> Custom Main Manifest checkbox). Here is an example:
<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
<application ...>
...
<meta-data
android:name="AdaptyPublicSdkKey"
android:value="PUBLIC_SDK_KEY" />
<meta-data
android:name="AdaptyObserverMode"
android:value="false" />
</application>
</manifest>
Configurational options:
Parameter | Presence | Description |
---|---|---|
AdaptyPublicSDKkey | required | The key you can find in the Public SDK key field of your app settings in Adapty: App settings-> General tab -> API keys subsection. Make sure you use the Public SDK key for Adapty initialization, the Secret key should be used for server-side API only. |
AdaptyObservermode | optional | A boolean value that controls Observer mode. Turn it on if you handle purchases and subscription status yourself and use Adapty for sending subscription events and analytics. Default value is false .🚧 When running in Observer mode, Adapty SDK won't close any transactions, so make sure you're handling it. |
Use Adapty Unity Plugin
- Create a script to listen to Adapty events. Name it
AdaptyListener
in your scene. We suggest using theDontDestroyOnLoad
method for this object to ensure it persists throughout the application's lifespan.
Adapty uses AdaptySDK
namespace. At the top of your script files that use the Adapty SDK, you may add
using AdaptySDK;
- Subscribe to Adapty events:
using UnityEngine;
using AdaptySDK;
public class AdaptyListener : MonoBehaviour, AdaptyEventListener {
void Start() {
DontDestroyOnLoad(this.gameObject);
Adapty.SetEventListener(this);
}
public void OnLoadLatestProfile(Adapty.Profile profile) {
// handle updated profile data
}
}
Set up the logging system
Adapty logs errors and other important information to help you understand what is going on. There are three levels available:
error | Only errors will be logged. |
---|---|
warn | Errors and messages from the SDK that do not cause critical errors, but are worth paying attention to will be logged. |
info | Errors, warnings, and serious information messages, such as those that log the lifecycle of various modules will be logged. |
verbose | Any additional information that may be useful during debugging, such as function calls, API queries, etc. will be logged. |
You can call SetLogLevel()
method in your app before configuring Adapty.
Updated 18 days ago