Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Ads and Promo in the same Placement. Code?

Discussion in 'Unity Ads & User Acquisition' started by kreso, Jul 28, 2019.

Thread Status:
Not open for further replies.
  1. kreso

    kreso

    Joined:
    Sep 7, 2013
    Posts:
    145
    Hello there,

    I am implementing the new Monetization SDK in my game. Sounds exciting!

    2 of my placements have Ads & Promo content enabled, and one of my placements has only Promo enabled.

    1. Is this the correct way to show all placements with the same code?

    Code (CSharp):
    1.  
    2.  
    3. void Show(string placementId)
    4. {
    5.  
    6.     ShowAdCallbacks options = new ShowAdCallbacks ();
    7.     options.finishCallback = OnUnityAdsDidFinish;
    8.  
    9.     PlacementContent placementContent = Monetization.GetPlacementContent (placementId);
    10.     PromoAdPlacementContent promoContent = placementContent as PromoAdPlacementContent;
    11.     ShowAdPlacementContent adContent = placementContent as ShowAdPlacementContent;
    12.  
    13.     if(promoContent != null)
    14.     {
    15.         MyPromoAdapter adapter = Monetization.CreateNativePromoAdapter (promoContent) as MyPromoAdapter;
    16.         promoContent.Show(options);
    17.     } else if (adContent != null) {
    18.         adContent.Show(options);
    19.     } else {
    20.         // Mighty computer algorithm decided no ad should be shown (or no ads available).
    21.     }
    22. }
    23.  
    24. public class MyPromoAdapter : INativePromoAdapter
    25. {
    26.     public void OnShown() {}
    27.     public void OnShown(PromoShowType type) { }
    28.     public void OnClosed() { }
    29.     public void OnClicked() {
    30.         // Initiate purchase here.
    31.     }
    32.     public PromoMetadata metadata { get; }
    33. }
    34.  
    35.  
    2. What is the difference between adapter.OnShown(
    PromoShowType.Full) and adapter.OnShown(PromoShowType.Preview)

    3. Why is there no 'onAdFailed' callback when using Monetization namespace?
    The 'Advertising.IUnityAdsListener.OnUnityAdsDidError' callback is very useful. Any way to know ad failed via Monetization namespace, or perhaps Monetization always finishes?

    4. How to access multiple items (bundle) of products from 'adapter'?
    I assume if it is only 1 product, the info will be inside the 'metadata.premiumProduct
    What is the best way to charge for a bundle? I assume creating IAP with a certain price point and then simply charge it once (instead of charging multiple IAPs)?

    Any pointers are helpful!

    Kind regards
     
    Last edited: Jul 28, 2019
  2. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    I'm not sure if this will cause issues when you try to cast placementContent that isn't a Promo into that type. One alternative would be to use GetType to check and then cast appropriately:

    Code (CSharp):
    1. if (placementContent.GetType() == typeof(ShowAdPlacementContent))
    2. {
    3.     Debug.Log("Showing Ad - Placement: " + placementContent.placementId);
    4.     ShowAdPlacementContent showAd = (ShowAdPlacementContent)placementContent;
    5. }
    6.  
    7. if (placementContent.GetType() == typeof(PromoAdPlacementContent))
    8. {
    9.     Debug.Log("Showing Promo - Placement: " + placementContent.placementId);
    10.     PromoPlacementContent promoAd = (PromoPlacementContent)placementContent;
    11. }
    Also, the INativePromoAdapter is only necessary if you are using native promos, which means you are using your own in-game assets to offer the IAP. (Normal promo uses an image you configure in our dashboard.) And in case it isn't clear, it is expected that you will call the adapter methods when you are rendering your native promo and after it has been closed; they are not callbacks that will be triggered automatically.
    https://unityads.unity3d.com/help/beta/native-promo

    I don't know. My guess would be PromoShowType is the basis for a feature that isn't completed yet. I would stick with OnShown() without the parameter.

    Yes, the same callback will be used for success and failure. In your finishCallback, you will receive a ShowResult that has the state Completed, Skipped, or Error.

    The promo that is shown will only be for a single product ID. The product ID will be defined in the app store dashboard (Google Play Store or iOS App Store). If you want to have a promo for a bundle of items, you should create that bundle as a separate IAP in the app store.
     
    kreso likes this.
  3. kreso

    kreso

    Joined:
    Sep 7, 2013
    Posts:
    145
    @ap-unity This is VERY helpful.

    Thank you
     
Thread Status:
Not open for further replies.