Unity SDK Integration Guide
Requirements
Before you Begin
- You must have an active AdGem account
- You must add your App to your account
- The AdGem Unity SDK supports devices Android 9.0 and higher and iOS 15.0 and higher
- The AdGem Unity SDK is compatible with apps built in Unity 2018 and higher
Integration
Step 1. Import AdGem Unity SDK Package
First, you will need to download the latest AdGem Unity SDK Download v2.0.7
Once you have downloaded the AdGem SDK, open your Unity project, double click AdGemSdk.unitypackage and import all files.
Step 2. Add AdGemPrefab To Your Scenes
Inside the Plugins/AdGemSdk folder, you will find a prefab called AdGemPrefab
. Add this to your first scene. It will automatically persist throughout the game.
Step 3. Initialize AdGem SDK
In the first scene of your app, call the following function in the Start()
method.
Parameter | Type | Description |
---|---|---|
AppID | integer | Your AdGem app ID, found in the Adgem Publisher dashboard. |
UsesInterstitialVideos | boolean | Whether or not your app shows interstitial (non-rewarded) videos. |
UsesRewardVideos | boolean | Whether or not your app shows rewarded videos. |
UsesOfferWall | boolean | Whether or not your app shows the offer wall. |
Example
#if UNITY_IOS
AdGem.startSession(1487, true, true, true);
#else if UNITY_ANDROID
AdGem.startSession(1493, true, true, true);
#endif
Step 4. Ad Units
Before showing a rewarded-video ad, check if AdGem.rewardVideoReady is true. If so, you can start an ad by calling:
Before showing a interstitial ad, check if AdGem.interstitialVideoReady is true. If so, you can start an ad by calling:
Before showing the offer wall, check if AdGem.offerWallReady is true. If so, you can show the offer wall by calling:
Step 5. Delegate Methods
For being alerted when a reward video is ready, use:
For being alerted when a interstitial video is ready, use:
For being alerted when a video ad actually starts playing, use:
To be alerted when a user successfully completes an offer on the offer wall, use:
For the Offer Wall, the delegate is of typeAction<int>
, with the integer value being the amount of in-game virtual currency received from the offer.
Full list of the delegate methods available to use:
Step 6. Set the player id (for non games, the unique identifier for a user)
For increased fraud protection, we highly recommend you set the player_id (a unique id for your user) parameter.
AdGem.player_id = "player123";
AdGem.player_age = 18;
AdGem.player_gender = AdGem.Gender.Female;
AdGem.player_payer = false;
AdGem.player_iap_total_usd = 0;
AdGem.player_created_at = "date value";
AdGem.player_level = 7;
AdGem.placement = 2;
AdGem.c1 = "your custom value 1";
AdGem.c2 = "your custom value 2";
AdGem.c3 = "your custom value 3";
AdGem.c4 = "your custom value 4";
AdGem.c5 = "your custom value 5";
Important Notes
- If boolean
AdGem.videoIsPlaying
is true, it is important to suppress user input until the video-finished-playing Action is raised. - When you build for iOS, you must include the
StoreKit.framework
in your XCode project within the build phases tab. - It appears that Unity has an issue that will crash an Android app if a new scene tries to load at the same instant that an Intent opens another app (such as a browser). It is recommended that you do not put any scene loading commands in the video complete delegate functions.
- If your app was built in Unity 2017 and your receiving the error “Unable to instantiate prefab”, you’ll need to make a slight adjustment to the AdGem Unity plugin within the text editor. Adjust the AdGemPrefab.prefab in the text editor:
from
m_SourcePrefab
tom_ParentPrefab
fromm_IsPrefabAsset
tom_IsPrefabParent
. - If you have an Android manifest file in your assets/plugins/android folder, make sure not to import the android manifest in the adgem package. Instead, add the following code inside the application block of your existing manifest:
<activity
android:name="com.kctech.unity.WebViewActivity"
android:alwaysRetainTaskState="true"
android:clearTaskOnLaunch="false"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density"
android:hardwareAccelerated="true"
android:launchMode="singleTask"
android:screenOrientation="fullSensor">
</activity>
Optional Parameters
You can optimize your revenue potential by segmenting your users using the optional parameters available in the Unity SDK. Please visit Optional Parameters to learn more.
Additional Options
You can optionally pre-load the Offer Wall before showing it to the user by using loadOfferWallBeforeShowing
.
You can enable verbose logging by setting verboseLogging
to true. By default, verbose logging is disable.
Postback Setup
If you have opted for a “Server Postback”, on each successful offer completion by a user AdGem will send a GET request to your server. Please visit our guide on Server Postback Setup to learn more.
Updated on October 6, 2023