Important note: Your game must initialize Unity IAPAbbreviation of Unity In App Purchase
See in Glossary before initializing Unity Ads for IAP Promo to work.
This integration guide covers four major steps:
To use IAP Promo, you need to:
IAP Promo requires a supported version of the Unity IAP SDK (1.17+). To acquire the latest IAP SDK, either enable In-App Purchasing in the Services window (Window > Services), or import it from the Asset storeA growing library of free and commercial assets created by Unity and members of the community. Offers a wide variety of assets, from textures, models and animations to whole Project examples, tutorials and Editor extensions. More info
See in Glossary. If you’re enabling it from the Services window, be sure to Import the Asset package when prompted.
See documentation on Setting up IAP for additional information.
IAP Promo requires a supported version of the Unity Ads SDK. Unity recommends acquiring the latest Ads SDK (3.0+) by importing it from the Asset store.
See Setting up Ads for Unity for additional information.
With the required services set up, you can implement them in your game.
There are two options for initialization: codeless or scripting.
Codeless IAP handles initialization for you. If you use Codeless IAP initialization, you must call the Unity Ads initialization method elsewhere in your code.
To use Codeless IAP, populate a Product Catalog, then create an IAP Listener to fetch that catalog:
In the Editor, select Window > UnityIAP > IAP Catalog to open the IAP Catalog window. This window lists all of your previously configured Products. You must have at least one Product configured in your Product Catalog. For a complete walkthrough on setting up Products, see Codeless IAP.
In the IAP Catalog window, select App Store Export > Cloud JSON to export a local copy of the Product Catalog.
Create an IAP Listener. Select Window > Unity IAP > Create IAP Listener, and add it to the first scene of your game. The listener fetches your Product Catalog as soon as the game boots. This avoids errors where the game requests Promotions but a Product isn’t ready because the codeless button hasn’t appeared in the scene yet.
If you do not use Codeless IAP, you must initialize Unity IAP manually through a script. See the following code example:
using UnityEngine;
using UnityEngine.Purchasing;
public class IAPManager : MonoBehaviour, IStoreListener {
private IStoreController controller;
//The following products must be added to the Product Catalog in the Editor:
private const string coins100 = "100.gold.coins";
private const string coins500 = "500.gold.coins";
public int coin_count = 0;
void Awake () {
StandardPurchasingModule module = StandardPurchasingModule.Instance ();
ProductCatalog catalog = ProductCatalog.LoadDefaultCatalog ();
ConfigurationBuilder builder = ConfigurationBuilder.Instance (module);
IAPConfigurationHelper.PopulateConfigurationBuilder (ref builder, catalog);
UnityPurchasing.Initialize (this, builder);
}
public void OnInitialized (IStoreController controller, IExtensionProvider extensions) {
this.controller = controller; Debug.Log ("Initialization Successful");
}
public void OnInitializeFailed(InitializationFailureReason error) {
Debug.Log ("UnityIAP.OnInitializeFailed (" + error + ")")
}
public void OnPurchaseFailed (Product item, PurchaseFailureReason reason) {
Debug.Log("UnityIAP.OnPurchaseFailed (" + item + ", " + reason + ")");
}
public PurchaseProcessingResult ProcessPurchase (PurchaseEventArgs e) {
string purchasedItem = e.purchasedProduct.definition.id;
switch (purchasedItem) {
case coins100: Debug.Log ("Congratulations, you are richer!");
coin_count += 100;
Debug.Log ("IAPLog: Coin count: " + coin_count);
break;
case coins500: Debug.Log ("Congratulations, you are richer!");
coin_count += 500;
Debug.Log ("IAPLog: Coin count: " + coin_count);
break;
}
return PurchaseProcessingResult.Complete;
}
public void Buy(string productId) {
Debug.Log ("UnityIAP.BuyClicked (" + productId + ")");
controller.InitiatePurchase (productId);
}
}
You must also initialize Unity Ads, whether or not you use the Codeless or manual IAP initialization method. The following code sample illustrates an initialization method to invoke:
using UnityEngine;
using UnityEngine.Monetization;
public class AdManager : MonoBehaviour {
public bool testMode = true;
private const string adPlacement = "video";
private const string promoPlacement = "promo";
#if UNITY_IOS
private string gameId = "0000000"; // Your __iOS__Apple's mobile operating system. [More info](iphone.html)<span class="tooltipGlossaryLink">See in [Glossary](Glossary.html#iOS)</span> game ID here
#elif UNITY_ANDROID
private string gameId = "9999999"; // Your Android game ID here
#else
private string gameId = "0123456"; // Prevents Editor Errors
#endif
private void Awake () {
if (Monetization.isSupported && !Monetization.isInitialized) {
Monetization.Initialize (gameId, testMode);
}
}
public void ShowVideoAd () {
ShowAdPlacementContent ad = Monetization.GetPlacementContent (adPlacement) as ShowAdPlacementContent;
ad.Show ();
}
public void ShowPromo () {
PromoAdPlacementContent promo = Monetization.GetPlacementContent (promoPlacement) as PromoAdPlacementContent;
promo.Show ();
}
}
Navigate to the Monetization section of the Operate Dashboard to configure your IAP Promo offers:
Use the Editor Play mode to check that a test ad appears when the Placement makes its request.
In order to test Promos, you must have Promo assets configured and build to a device. If you initialize in test mode, you will see a test Promo creative. To see real promotional creative assets, you must build the game to a device in production mode.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Is something described here not working as you expect it to? It might be a Known Issue. Please check with the Issue Tracker at issuetracker.unity3d.com.
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thanks for helping to make the Unity documentation better!