Admob rewarded ad callbacks

1,677 views
Skip to first unread message

Julian Neil

unread,
Oct 4, 2023, 6:33:15 PM10/4/23
to Google Mobile Ads SDK Developers
Hi there.

I'm having difficulty with callbacks when rewarded ads are shown.  I have followed the guide on setting up rewarded ads, and they appear in my application.  My difficulty is in covering all code paths once the ad is shown.

I am using the Unity Admob SDK.

I understand that when I want to show an ad I pass in a callback that is called when the user has earned a reward, e.g (snippets taken from your getting started guide ):
        rewardedAd.Show((Reward reward) =>
        {
            // TODO: Reward the user.
            Debug.Log(String.Format(rewardMsg, reward.Type, reward.Amount));
        });

I also understand that to track when the Ad is finished I need to add two additional event listeners.  e.g.

    // Raised when the ad closed full screen content.
    ad.OnAdFullScreenContentClosed += ()
    {
        Debug.Log("Rewarded Ad full screen content closed.");

        // Reload the ad so that we can show another as soon as possible.
        LoadRewardedAd();
    };
    // Raised when the ad failed to open full screen content.
    ad.OnAdFullScreenContentFailed += (AdError error) =>
    {
        Debug.LogError("Rewarded ad failed to open full screen content " +
                       "with error : " + error);

        // Reload the ad so that we can show another as soon as possible.
        LoadRewardedAd();
    };

As far as I can tell, there are three possible outcomes when i try to show an ad.
  1. The ad fails to show and no reward is given.  The OnAdFullScreenContentFailed event fires.
  2. The ad shows and a reward is given.  The RewardEarned callback is called, and the OnAdFullScreenContentClosed is called  - but the ordering is not defined and in some cases dependent on mediation partners
  3. The ad shows and no reward is given.  The OnAdFullScreenContentClosed is called.

The API design seems a little strange.  My application needs to prepare the UI when the ad is shown, and then to respond with appropriate feedback when the one of the three outcomes above is known.  
My question is: In my implementation, how am I supposed to distinguish between 2 and 3?  When I get the Closed event, do I have to check to see if I have already received a RewardEarned call, and if not - wait for it?  for how long? When do I know that the ad has been displayed but no reward given?  I am hoping that I am mistaken and that outcome 3 is not even possible. 

regards,
Julian

Mobile Ads SDK Forum Advisor

unread,
Oct 6, 2023, 8:19:23 AM10/6/23
to battered...@gmail.com, google-adm...@googlegroups.com

Hi,

Thank you for contacting the Mobile Ads SDK support team.

By reviewing your concern, I understand that you are having some concerns on rewarded ad callbacks. Thank you for sharing your valuable observations. 

Please find the callbacks scenarios below:

  1. The ad fails to show and no reward is given :  OnAdFullScreenContentFailed
  2. The ad shows and a reward is given : Callback order -  OnAdFullScreenContentClosed and RewardEarned
  3. The ad shows and no reward is given : After ad shows, reward will be given.

I would recommend following this article for better understanding.

Please reach out to us, if you need any further assistance.
 

This message is in relation to case "ref:_00D1U1174p._5004Q2pOzr0:ref"

Thanks,
 
Google Logo Mobile Ads SDK Team


Julian Neil

unread,
Oct 6, 2023, 3:40:52 PM10/6/23
to Google Mobile Ads SDK Developers
From my implementation logs, on Android using no mediation and just serving Admob test ads, your advice is incorrect on the callback order in case 2.  
Your linked article isn't even a technical article... It has no information that helps answer my question.

Please read my initial post, which is very detailed in its description of my problem.  Please forward this to a technical person who can give me technical assistance. To assist, I have copied my original text below - because it seems that you only receive individual responses without any context.

regards,
Julian
...

Mobile Ads SDK Forum Advisor

unread,
Oct 10, 2023, 10:20:59 PM10/10/23
to battered...@gmail.com, google-adm...@googlegroups.com
Hi Julian,

Thanks for your feedback. Let me try to answer your questions inline:


In my implementation, how am I supposed to distinguish between 2 and 3?
The OnAdFullScreenContentClosed callback is called automatically by the Google Mobile Ads SDK. The Show callback is also called automatically by the SDK. You shouldn't need to distinguish between the two scenarios or do any manual checking.


When I get the Closed event, do I have to check to see if I have already received a RewardEarned call, and if not - wait for it?
No, you do not have to check. The Show callback will either be called or it won't, given if the user has watched the video long enough to receive a reward. For Google ads, this typically happens before the OnAdFullScreenContentClosed callback is called. For other ads, the timing may vary due to factors such as network conditions but as long as you keep your reference to the rewarded ad and don't call destroy(), the Show callback will happen as soon as the reward is granted.


When do I know that the ad has been displayed but no reward given?
It is possible a user may close the ad before the reward is granted. Is it possible that the OnAdFullScreenContentClosed callback happens without the Show callback happening. You could add a boolean to keep track of this. 

In summation, the SDK will handle when the reward is granted and when the ad is closed. If your app includes implementing some logic depending if the user receives a reward or not the results may vary based on an ad-to-ad basis. 

Thanks,
Justin

 

ref:_00D1U1174p._5004Q2pOzr0:ref

Julian Neil

unread,
Oct 11, 2023, 8:03:02 PM10/11/23
to Mobile Ads SDK Forum Advisor, google-adm...@googlegroups.com
Hi Justin,
Thanks for your reply.  

I'm not sure why you say I shouldn't need to distinguish between the two scenarios.  I have to give feedback to the user.  They need to know when there was a failure during displaying the ad, they need to know when a reward was given after they watched (enough of) the ad, and they need to know when there was no failure but a reward was not given.  Ideally the UI feedback would be different in each case.  

You suggest that the Show callback will happen as long as destroy() is not called.  This is counter to the flow of all documentation and sample applications you provide, e.g. https://developers.google.com/admob/unity/rewarded#preload_the_next_rewarded_ad   .  In your sample apps and in your documentation the ad is destroyed in the OnAdFullScreenContentClosed and the OnAdFullScreenContentFailed callbacks, regardless of whether the Show callback is called.   According to your information this could prevent the Show callback happening in circumstances where it should be called.  So now I'm not sure which advice to follow here.  Are your samples and documentation wrong? 

You suggest adding a boolean to keep track of whether the Show callback has been called.  As a coder - this suggestion makes no sense and goes to the core of my original question.
Say I use a boolean to indicate that the ad has been rewarded.  I would have to initialise it to false, and set it to true in the Show callback.   When I get the OnAdFullScreenContentClosed, I could check the flag.  If it is true, I know that the Show callback was called before the Closed callback, and all is hunky dory - because I know a reward was given.   If in the Closed callback the flag is still false, I dont know if a reward is coming later, so I dont know the outcome.  I have to wait until either the Show callback is called  -   or it isn't called.  But I'm not a magician so I can't execute code when something isn't called (without implementing dodgy kludges).    With your current API how am I supposed to know when the Show callback isn't called (and isn't going to be called)?  If you're suggesting I just wait for a bit - how long should I wait before deciding it isn't going to be called?

regards,
Julian

Mobile Ads SDK Forum Advisor

unread,
Oct 12, 2023, 2:45:36 PM10/12/23
to battered...@gmail.com, google-adm...@googlegroups.com
Hi Julian,

As far as providing feedback to the user so they know when a reward was given after they watched enough of the ad, the creative itself should provide a visual cue on the close button with text saying "Reward granted" when the user has earned a reward. As soon as this happens, the Show callback is called. If there was no reward given, the close button will not say "Reward granted". This may happen in the case if a user closes the ad early. Users who exit out of an ad early will be prompted with an on screen dialogue mentioning if they exit they will not receive a reward. 

"You suggest that the Show callback will happen as long as destroy() is not called" - Please read my messages carefully. The Show callback depends on if the user has watched enough of the ad to receive a reward. As far as our documentation and samples are concerned, that would be the source of truth. 

For the rest of the questions, let me forward this query to our Unity developer who will be able to provide a more idiomatic response.

cha...@viquasoft.com

unread,
Aug 12, 2024, 12:45:36 AM8/12/24
to Google Mobile Ads SDK Developers
Hello, 

Sorry for necroing this old discussion thread, but I am implementing Admob on Unity and have the exact same question.

Can someone let me know how to distinguish between OnAdFullScreenContentClosed where a reward was given or not given?
Can we expect the Show RewardEarned callback to always happen before the OnAdFullScreenContentClosed event? Or after?
If after, then how long must we wait until we can be sure that the player did not earn a reward?

Mobile Ads SDK Forum Advisor

unread,
Aug 12, 2024, 2:13:53 PM8/12/24
to cha...@viquasoft.com, google-adm...@googlegroups.com
Hi Canon,

OnAdFullScreenContentClosed occurs when the the ad is closed and it is possible to close the ad without receiving a RewardCallback for instance when the user closes the ad prematurely. 

 
This message is in relation to case "ref:!00D1U01174p.!5004Q02pOzr0:ref" (ADR-00201683)

Thanks,
 
Google Logo
Nicholas Ventimiglia
Mobile Ads SDK Team


Reply all
Reply to author
Forward
0 new messages