Search Unity

How do you give different rewards for rewarded ads

Discussion in 'Unity Ads & User Acquisition' started by WhiteHotGames, Aug 2, 2020.

  1. WhiteHotGames

    WhiteHotGames

    Joined:
    Jun 11, 2018
    Posts:
    3
    Hi all,

    Hopefully there's a straightforward solution to this so I'll get straight to it.

    I've set up the Unity Ads script using UnityEngine.Advertisements instead of the old Monetization, but I've come across some minor issues with it that I'm struggling to overcome without some workaround.

    Using Monetization I could create an ad, have a callback for that ad and set the rewards to give at the end. In the new system you don't seem to set which callback the ad goes to, so there's just one for all ads, leaving me wondering how I can give different rewards.

    In my AdManager script there are 2 functions (pasted below) that are used, one to play the ad, one for the callback to give rewards. But if I can't set which callback is used by which ad, then I can only call "ShowRewardedVideo" from any ad button, and then it will always give the same rewards.

    Hopefully this make sense, below are the two functions within the AdManager script that I'm using. Any help is appreciated.

    Code (CSharp):
    1.  
    2. public void ShowRewardedVideo()
    3.     {
    4.         if (Advertisement.IsReady(myPlacementId))
    5.         {
    6.             Advertisement.Show(myPlacementId);
    7.         }
    8.         else
    9.         {
    10.             print("Rewarded video not ready");
    11.         }
    12.     }
    13.  
    14.     public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
    15.     {
    16.         // Define conditional logic for each ad completion status:
    17.         if (showResult == ShowResult.Finished)
    18.         {
    19.             print("Ad completed");
    20.         }
    21.         else if (showResult == ShowResult.Skipped)
    22.         {
    23.             print("Ad skipped");
    24.         }
    25.         else if (showResult == ShowResult.Failed)
    26.         {
    27.             print("Ad failed");
    28.         }
    29.     }
    30.  

    Here is an example of what I'm trying to do from my game:

    Rewarded Ad 1
    The player presses the button, watches the ad, and is given 100 coins

    Reward Ad 2
    The player presses the button, watches the ad, and is loaded into a new level

    It feels like the only way I can see it's intended to work is by adding a new placement ID for every rewarded ad you have in your game... which seems crazy as then surely you're juggling multiple ads to be ready to show, instead of 1/2.
     
    Last edited: Aug 2, 2020
  2. Unity_Adamski

    Unity_Adamski

    Unity Technologies

    Joined:
    Jul 20, 2020
    Posts:
    110
    Hi WhiteHotGames,

    In this new system the advertisement will call OnUnityAdsDidFinish() when the advertisement ends. When this is called the SDK will provide you with the placementId of the ad and an ad result.

    The ad result has 3 main states:
    • Finished - This is means the user watched the ad all the way through
    • Skipped - The user has pressed the skip button if it is available
    • Failed - The ad as failed to show correctly
    You should provide the player with a reward if the ad returns 'finished' (Line:19). You can use the placementId to determine what reward should be given for each placement. If you want multiple placementIds to have similar behavior you could edit the placementId's id to contain a key string that you could then look for.

    I hope that's helped
     
  3. kyle-unity

    kyle-unity

    Unity Technologies

    Joined:
    Jan 6, 2020
    Posts:
    336
    If you don't want to have multiple placements for different rewards, you could also selectively only add components as listeners when an ad is being shown for that reward. For example, if the 100 coins reward button is pressed, it can add itself as a listener as the ad is being shown, and then remove itself once the ad finishes. That way, you only ever have one listener registered at a time and bypass the issue of multiple callbacks firing.
     
  4. WhiteHotGames

    WhiteHotGames

    Joined:
    Jun 11, 2018
    Posts:
    3
    Thanks for your help guys, I'm going to review the options and see which works best for me.

    Out of curiosity, if I did add multiple placementIDs for give different rewards, would it affect the live game?
    For example, I currently have "rewardedVideo" as my rewarded ad placementID in my live game. If I were to name the placementIDs more appropriately based on where they're triggered, and edited this one, would it break in the live version as it's looking for "rewardedVideo", which no longer exists?
     
  5. Unity_Adamski

    Unity_Adamski

    Unity Technologies

    Joined:
    Jul 20, 2020
    Posts:
    110
    Too my knowledge changing the placementId in the dashboard without changing the id in the live game will cause ads to stop showing. For now I recommend you setup new placements and hook them up in the next update to your app. This will ensure you don't break anything for your current users.
     
    WhiteHotGames likes this.
  6. Macaquito69

    Macaquito69

    Joined:
    Apr 24, 2020
    Posts:
    15
    Hi @WhiteHotGames, did you get to a solution? could you please share with me? I am trying to do this for 2 weeks now.
     
  7. WhiteHotGames

    WhiteHotGames

    Joined:
    Jun 11, 2018
    Posts:
    3
    Hi @Macaquito69

    I ended up creating multiple new placement IDs in the Unity dashboard for each ad use in game. This way when I want to trigger an ad I send the string of the ad e.g. "DoubleCoinsResults" to the AdManager, which plays the ad and runs the appropriate callback for the Placement ID, where you can then give the rewards you want by using a switch statement.

    It's a bit lengthier than my old version which would just have the ad code in each script where needed and have it's own callback, but much more efficient.

    Hope that helps!
     
    Atermizor likes this.
  8. ajeets1978

    ajeets1978

    Joined:
    Mar 10, 2019
    Posts:
    25
    How do you achieve the same with Unity Mediation Reward Ad ?
     
  9. shahin2019

    shahin2019

    Joined:
    Mar 17, 2019
    Posts:
    19
    I wrote below codes for unity 2019.1.9 but when now I transfer to unity 2020.3.45 so I receive Error in scripts RewardedAdsButton.cs Aon below red color codes :

    public class RewardedAdsButton : MonoBehaviour, IUnityAdsListener {


    and
    public void OnUnityAdsDidFinish (string placementId, ShowResult showResult) {

    and I receive Errors on script codes: androidplatform.cs on red color :
    m_UnityAdsPurchase?.Initialize(this);



    so how can I resolve it unity 2020.3.45?
    Thanks
     
  10. Yasuyuki

    Yasuyuki

    Unity Technologies

    Joined:
    Sep 11, 2014
    Posts:
    153
    IUnityAdsListener and ShowResult have been deprecated in 4.0.0. Please see the deprecated API docs.
    https://docs.unity.com/ads/en/manual/DeprecatedAPIClasses

    I'm not really sure what the type of this variable, but the error message that showed in your console could be a hint for those errors.
     
  11. shahin2019

    shahin2019

    Joined:
    Mar 17, 2019
    Posts:
    19
    Last edited: Feb 20, 2023
  12. Yasuyuki

    Yasuyuki

    Unity Technologies

    Joined:
    Sep 11, 2014
    Posts:
    153
  13. shahin2019

    shahin2019

    Joined:
    Mar 17, 2019
    Posts:
    19
    I used SDK unity 2.1.0 for unity 2019.1.9 but I Now sdk unity 4.4.1 and unity 2020.3.45 And I receive Error on sdk unity 4.4.1 now

     
  14. Yasuyuki

    Yasuyuki

    Unity Technologies

    Joined:
    Sep 11, 2014
    Posts:
    153
    Did you use the asset store version of Unity Ads SDK? In that case you'll need to remove Unity Ads asset entirely from Assets folder when upgrading to the package manager version. The latest Advertisement package should include those interfaces.
     
    shahin2019 likes this.
  15. shahin2019

    shahin2019

    Joined:
    Mar 17, 2019
    Posts:
    19
    Thanks for help
    I reinstalled it and It worked but I have problem on new codes
    Please see photos

    How can I resolve problem
    Tganks