Unity IAP provides a simple webview interface for you to display IAP promotional assets through Placements. To control the rendering process for these assets, use Native Promo to implement custom promotional displays.
To use Native Promo, you must download and install the latest SDK (3.0+) from the Asset Store.
Follow the instructions for setting up IAP Placements, Products, and Promos, but note that you should not upload creative assets when configuring your IAP Products.
The SDK provides a Native Promo adapter interface with methods for handling promotional asset interactions. Use these methods in your custom scripts to inform the SDK when the Promo begins, finishes, and initiates the purchase flow.
Every developer’s Native Promo implementation varies greatly. The following abstract sample code illustrates an implementation.
using UnityEngine.Monetization;
public class NativePromoDisplay : MonoBehaviour {
PlacementContent placementContent = Monetization.GetPlacementContent (placementId);
PromoAdPlacementContent promoContent = placementContent as PromoAdPlacementContent;
INativePromoAdapter adapter = Monetization.CreateNativePromoAdapter (promoContent);
void ShowPromo () {
LogPromoInfo ();
// Use promoContent’s associated Product ID (e.g. adapter.metadata.premiumProduct.productID) to determine which assets to show
// Call adapter.OnShown () to tell the SDK the Promo has started, then execute your custom display for those assets
// Call adapter.OnClicked () to tell the SDK the player clicked the purchase button and to initiate the purchase flow
// Call adapter.OnClosed () to tell the SDK the Promo has ended
}
void LogPromoInfo () {
Debug.LogFormat ("Product ID: \t{0}", adapter.metadata.premiumProduct.productId);
Debug.LogFormat ("Localized Title: \t{0}", adapter.metadata.premiumProduct.localizedTitle);
Debug.LogFormat ("Localized Description: \t{0}", adapter.metadata.premiumProduct.localizedDescription);
Debug.LogFormat ("ISO Currency Code: \t{0}", adapter.metadata.premiumProduct.isoCurrencyCode);
Debug.LogFormat ("Localized Price: \t{0}", adapter.metadata.premiumProduct.localizedPrice);
Debug.LogFormat ("Localized Price String: \t{0}", adapter.metadata.premiumProduct.localizedPriceString);
}
}
Extends the ShowAdPlacementContent
class, providing functionality for IAP Promo content.
A Unity IAP Product object.
プロパティ | Retrieval method | Description |
---|---|---|
string productId |
GetProductId () |
An internal reference ID for the Product. |
string localizedTitle |
GetlocalizedTitle () |
A consumer-facing name for the Product, for store UI purposes. |
string localizedPriceString |
GetLocalizedPriceString () |
A consumer-facing price string, including the currency sign, for store UI purposes. |
double localizedPrice |
GetLocalizedPrice () |
The internal system value for the Product’s price. |
string isoCurrencyCode |
GetIsoCurrencyCode () |
The ISO code for the Product’s localized currency. |
string localizedDescription |
GetLocalizedDescription () |
A consumer-facing Product description, for store UI purposes. |
string productType |
GetProductType () |
Unity supports “Consumable”, “Non-consumable”, and “Subscription” Product Types. |
For more details on Product properties, see documentation on Defining Products.
Pass a PromoAdPlacementContent
object through this function to create a new INativePromoAdapter
. For example:
INativePromoAdapter adapter = Monetization.CreateNativePromoAdapter (promoContent);
This interface provides access methods for handling user interaction with promotional assets. Use these methods to pass in your custom assets and define expected behavior.
This property contains information for a PromoAdPlacementContent
object passed through the adapter.
public struct PromoMetadata {
public Product premiumProduct;
}
public PromoMetadata metadata { get; };
例
string cc = nativePromoAdapter.metadata.premiumProduct.isoCurrencyCode;
Call this function when the Promo is shown. It should include your custom method for displaying promotional assets.
void OnShown ();
Call this function when the player dismisses the Promo offer.
void OnClosed ();
Call this function when the player clicks the button to purchase the Product. It should initiate the purchase flow.
void OnClicked ();
Every developer’s Native Promo implementation varies greatly. The following abstract sample code illustrates an implementation.
@interface ViewController: UIViewController <USRVUnityPurchasingDelegate>
-(void) showPromo: (UMONPromoAdPlacementContent *) placementContent {
self.nativePromoAdapter = [[UMONNativePromoAdapter alloc] initWithPromo: placementContent];
UMONPromoMetaData *metaData = placementContent.metadata;
UPURProduct *product = metaData.premiumProduct;
NSString *price = (product == nil || product.localizedPriceString == nil) ? @"$0.99": product.localizedPriceString;
self.nativePromoView.hidden = NO;
NSString *title = [NSString stringWithFormat: @"Buy for only %@", price];
[self.purchaseButton setTitle: title forState: UIControlStateNormal];
[self.nativePromoAdapter promoDidShow];
}
// If the player clicked the purchase button:
(IBAction) purchaseButtonTapped: (id) sender {
[self.nativePromoAdapter promoDidClick];
[self.nativePromoAdapter promoDidClose];
self.nativePromoView.hidden = YES;
}
// If the player closed the promotional asset:
-(IBAction) promoCloseButtonTapped: (id) sender {
self.nativePromoView.hidden = YES;
[self.nativePromoAdapter promoDidClose];
}
- (void) loadProducts: (UnityPurchasingLoadProductsCompletionHandler) completionHandler {
// Retrieve your Products list (see purchasing integration docs)
}
- (void) purchaseProduct: (NSString *) productId
// Insert logic for successful or failed product purchase (see purchasing integration docs)
}
Read the purchasing integration for iOS documentation for more details on the USRVUnityPurchasingDelegate
class referenced here.
Extends the UMONShowAdPlacementContent
class, providing functionality for IAP Promo content.
A Unity IAP Product object.
プロパティ | Description |
---|---|
@property (strong, nonatomic, readonly) NSString *productId |
An internal reference ID for the Product. |
@property (strong, nonatomic, readonly) NSString *localizedTitle () |
A consumer-facing name for the Product, for store UI purposes. |
@property (strong, nonatomic, readonly) NSString *localizedPriceString |
A consumer-facing price string, including the currency sign, for store UI purposes. |
@property (nonatomic, readonly) double *localizedPrice |
The internal system value for the Product’s price. |
@property (strong, nonatomic, readonly) NSString *isoCurrencyCode |
The ISO code for the Product’s localized currency. |
@property (strong, nonatomic, readonly) NSString *localizedDescription |
A consumer-facing Product description, for store UI purposes. |
@property (strong, nonatomic, readonly) NSString *productType |
Unity supports “Consumable”, “Non-consumable”, and “Subscription” Product Types. |
For more details on Product properties, see documentation on Defining Products.
Pass a UMONPromoAdPlacementContent
object through this function to create a new UMONNativePromoAdapter
.
-(instancetype) initWithPromo: (UMONPromoAdPlacementContent *) promo;
This delegate provides access methods for handling user interaction with promotional assets. Use these methods to pass in your custom assets and define expected behavior.
This property contains information for a UMONPromoAdPlacementContent
object passed through the adapter.
@interface UMONPromoAdPlacementContent: UMONShowAdPlacementContent
-(instancetype) initWithPlacementId: (NSString *) placementId withParams: (NSDictionary *) params;
@property (nonatomic, strong, readonly) UMONPromoMetaData *metadata;
@end
Call this function when the Promo shows. It should include your custom method for displaying promotional assets.
-(void) promoDidShow;
-(void) promoDidShow: (UMONNativePromoShowType) showType;
You can pass a UMONNativePromoShowType
enum value to reference the preview type of your Promo asset. kNativePromoShowTypeFull
indicates a full promotional view, while kNativePromoShowTypePreview
indicates a minimized view that can expand to display the full Promo.
Call this function when the player dismisses the Promo offer.
-(void) promoDidClose;
promoDidClick
Call this function when the player clicks the button to purchase the Product. It should initiate the purchase flow.
-(void) promoDidClick;
Every developer’s Native Promo implementation varies greatly. The following abstract sample code illustrates an implementation.
UnityPurchasing.setAdapter (new UnityPurchasingAdapter ());
private class UnityPurchasingAdapter implements IPurchasingAdapter {
@Override
public void retrieveProducts (IRetrieveProductsListener listener) {
// Retrieve your Products list (see purchasing integration docs)
}
@Override
public void onPurchase (String productID, ITransactionListener listener, Map<String, Object> extras) {
// Insert logic for successful or failed product purchase (see purchasing integration docs)
}
private void showPromo (final PromoAdPlacementContent placementContent) {
final NativePromoAdapter nativePromoAdapter = new NativePromoAdapter (placementContent);
PromoMetadata metadata = placementContent.getMetadata ();
Product product = metadata.getPremiumProduct ();
String price = product == null ? "$0.99": product.getLocalizedPriceString ();
final View root = getLayoutInflater ().inflate (R.layout.unitymonetization_native_promo, (ViewGroup) findViewById (R.id.unityads_example_layout_root));
Button buyButton = root.findViewById(R.id.native_promo_buy_button);
Button closeButton = root.findViewById (R.id.native_promo_close_button);
buyButton.setText ("Buy now for only " + price + "!");
nativePromoAdapter.onShown();
buyButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick (View v) {
// Do purchase then call
nativePromoAdapter.onClosed ();
((ViewGroup)root).removeView (findViewById (R.id.native_promo_root));
}
});
closeButton.setOnClickListener (new View.OnClickListener () {
@Override
public void onClick(View v) {
nativePromoAdapter.onClosed ();
((ViewGroup)root).removeView (findViewById (R.id.native_promo_root));
}
});
}
Read the purchasing integration for Android documentation for more details on the UnityPurchasingAdapter
class referenced here.
Extends the ShowAdPlacementContent
class, providing functionality for IAP Promo content.
A Unity IAP product object.
プロパティ | Retrieval method | Description |
---|---|---|
String productId |
getProductId () |
An internal reference ID for the Product. |
String localizedTitle |
getlocalizedTitle () |
A consumer-facing name for the Product, for store UI purposes. |
String localizedPriceString |
getLocalizedPriceString () |
A consumer-facing price string, including the currency sign, for store UI purposes. |
Double localizedPrice |
getLocalizedPrice () |
The internal system value for the Product’s price. |
String isoCurrencyCode |
getIsoCurrencyCode () |
The ISO code for the Product’s localized currency. |
String localizedDescription |
getLocalizedDescription () |
A consumer-facing Product description, for store UI purposes. |
String productType |
getProductType () |
Unity supports “Consumable”, “Non-consumable”, and “Subscription” Product Types. |
For more details on Product properties, see documentation on Defining Products.
This delegate provides access methods for handling user interaction with promotional assets. Use these methods to pass in your custom assets and define expected behavior. Pass a PromoAdPlacementContent
object through the NativePromoAdapter
function to create a new adapter. For example:
final NativePromoAdapter nativePromoAdapter = new NativePromoAdapter (placementContent);
This property contains information for a PromoAdPlacementContent
object passed through the adapter.
public PromoMetadata getMetadata ();
Call this function when the Promo is shown. It should include your custom method for displaying promotional assets.
public void onShown (NativePromoShowType type);
You can pass a NativePromoShowType
enum value to reference the preview type of your Promo asset. FULL
indicates a full promotional view, while PREVIEW
indicates a minimized view that can expand to display the full Promo.
Call this function when the player dismisses the Promo offer.
public void onClicked
Call this function when the player clicks the button to purchase the Product. It should initiate the purchase flow.
public void promoClicked;
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?
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:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.