Unity Events not firing for AdMob

858 views
Skip to first unread message

Roberto Rodriguez

unread,
Feb 2, 2019, 5:13:10 AM2/2/19
to Google Mobile Ads SDK Developers
Hi,

I've been trying to implement the events for a rewarded video in a project i'm doing in Unity. The rewarded video shows up finely, but the Events don't seem to fire up, and therefore can't reward my user or other things.

I've searched in every forum, and one of the things i've tried is dispatching the events to the main threads, but that don't seem to work either, and i don't know what to do anymore. 

Here under i post my code. I've erased my app ID and unit ID here, but they are in my original code. The Interstitial is shown when "Game over" happens from an external class, and the rewarded video is shown when the user chooses to in a pop-up window, which is also proceeding from another class.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using GoogleMobileAds.Api;

public class Admanager : MonoBehaviour {
    private InterstitialAd interstitial;
    private RewardBasedVideoAd rewardBasedVideo;
  
    public void Start()
    {
        UnityMainThreadDispatcher.Instance().Enqueue(() => Debug.Log("This is executed from the main thread"));
       
        // Initialize the Google Mobile Ads SDK.
        MobileAds.Initialize(appId);
        //this.RequestInterstitial();
        this.rewardBasedVideo = RewardBasedVideoAd.Instance;

        // Called when an ad request has successfully loaded.
        rewardBasedVideo.OnAdLoaded += HandleRewardBasedVideoLoaded;
        // Called when an ad request failed to load.
        rewardBasedVideo.OnAdFailedToLoad += HandleRewardBasedVideoFailedToLoad;
        // Called when an ad is shown.
        rewardBasedVideo.OnAdOpening += HandleRewardBasedVideoOpened;
        // Called when the ad starts to play.
        rewardBasedVideo.OnAdStarted += HandleRewardBasedVideoStarted;
        // Called when the user should be rewarded for watching a video.
        rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded;
        // Called when the ad is closed.
        rewardBasedVideo.OnAdClosed += HandleRewardBasedVideoClosed;
        // Called when the ad click caused the user to leave the application.
        rewardBasedVideo.OnAdLeavingApplication += HandleRewardBasedVideoLeftApplication;

        this.RequestRewardBasedVideo();
        this.RequestInterstitial();
      
      
    }

 
    // Update is called once per frame
    void Update () {
       
    
    }

    public void playInter(){
        if (this.interstitial.IsLoaded())
        {
            this.interstitial.Show();
          
        }

    }

    public void playReward(){
        if (rewardBasedVideo.IsLoaded())
        {
            rewardBasedVideo.Show();
        }

    }

    public void destroyInter(){
        interstitial.Destroy();
    }



    private void RequestRewardBasedVideo()
    {

        


        // Create an empty ad request.
        AdRequest request = new AdRequest.Builder().Build();
        // Load the rewarded video ad with the request.
        this.rewardBasedVideo.LoadAd(request, adUnitId);
    }

    private void RequestInterstitial()
    {

       

        // Initialize an InterstitialAd.
        this.interstitial = new InterstitialAd(adUnitId);

        // Create an empty ad request.
        AdRequest request = new AdRequest.Builder().Build();
        // Load the interstitial with the request.
        this.interstitial.LoadAd(request);

    }

 
    public void HandleRewardBasedVideoLoaded(object sender, System.EventArgs args)
    {
        MonoBehaviour.print("HandleRewardBasedVideoLoaded event received");
    }

    public void HandleRewardBasedVideoFailedToLoad(object sender, AdFailedToLoadEventArgs args)
    {
        MonoBehaviour.print(
            "HandleRewardBasedVideoFailedToLoad event received with message: "
                             + args.Message);
    }

    public void HandleRewardBasedVideoOpened(object sender, System.EventArgs args)
    {
        MonoBehaviour.print("HandleRewardBasedVideoOpened event received");
       
    }

    public void HandleRewardBasedVideoStarted(object sender, System.EventArgs args)
    {
        MonoBehaviour.print("HandleRewardBasedVideoStarted event received");
       
    }

    public void HandleRewardBasedVideoClosed(object sender, System.EventArgs args)
    {
        MonoBehaviour.print("HandleRewardBasedVideoClosed event received");
        this.RequestRewardBasedVideo();
    }

    public void HandleRewardBasedVideoRewarded(object sender, Reward args)
    {
        string type = args.Type;
        double amount = args.Amount;
        MonoBehaviour.print(
            "HandleRewardBasedVideoRewarded event received for "
                        + amount.ToString() + " " + type);
        
       
    }

    public void HandleRewardBasedVideoLeftApplication(object sender, System.EventArgs args)
    {
        MonoBehaviour.print("HandleRewardBasedVideoLeftApplication event received");
    }
   



  

}


Will appreciate any help, thank you very much!!

mobileadssdk...@google.com

unread,
Feb 4, 2019, 1:27:01 AM2/4/19
to Roberto Rodriguez, Google Mobile Ads SDK Developers
Hi Roberto,

Thank you for the details provided.

Looking at your code snippets, sending the Ad Request on Start() as well as implementing the Ad events should have been enough to achieve your goal.

That said, could you test this with our sample app and let us know your findings?

For us to test on our end, could you provide to us your Ad Unit Id using Reply privately to author option?

Regards,
Ivan Bautista
Mobile Ads SDK Team




--

---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-admob-ads-sdk/bab2a98f-c15a-468c-84d8-2888e9ee636d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Roberto Rodriguez

unread,
Feb 4, 2019, 5:03:42 AM2/4/19
to Google Mobile Ads SDK Developers
Thank you, i'll let you know my findings!

Roberto Rodriguez

unread,
Feb 4, 2019, 9:03:03 AM2/4/19
to Google Mobile Ads SDK Developers
So after implementing my code inside the sample scene, the events still don't seem to fire up.
Even the NativeAd code that comes included with the SampleScene doesn't seem to fire any events; this is the log for the execution of the game (screenshot included).

I've ran out of ideas

thanks!
Screen Shot 2019-02-04 at 3.02.19 PM.png
Message has been deleted

Lune Tech

unread,
Oct 3, 2019, 5:52:32 PM10/3/19
to Google Mobile Ads SDK Developers
I'm having the same issue. Not even the sample provided fires off any event.

Mobile Ads SDK Forum Advisor Prod

unread,
Oct 3, 2019, 8:54:39 PM10/3/19
to lunet...@gmail.com, google-adm...@googlegroups.com

Hi there,

Thank you for reaching out to us.

Could you clarify on what you meant by the "sample not firing off any event"? Were you able to replicate this on a device? If yes, could you kindly provide the details below (via Reply privately to author) so that I can investigate the issue?

  • Copy of the sample project with the issue reproduced
  • Ad unit IDs affected
  • Unity version
  • AdMob .unitypackage version
  • Play Store link (if the issue occurs on one of your published apps as well)


Regards,
Ziv Yves Sanchez
Mobile Ads SDK Team



ref:_00D1U1174p._5001UKM8u7:ref

Mobile Ads SDK Forum Advisor Prod

unread,
Oct 3, 2019, 11:44:21 PM10/3/19
to lunet...@gmail.com, google-adm...@googlegroups.com

Hi there,

Thank you for providing the requested details in private.

I tested the sample project using the versions of the Unity engine and the AdMob plugin that you've provided, and can confirm that it was working properly on my end. With that in mind, kindly see below for my clarifications on a few points that you've raised:

  • According to the googlemobileadsdemoscript.cs and https://developers.google.com/admob/unity/banner, it shows the MonoBehaviour.print methods which is supposed to called when the event is called. I want to use OnAdLoaded and OnInterstitialLoaded events, but even though the ads are loaded, those events never get triggered.
    • For clarification, the events are being triggered properly. The reason why the MonoBehavior.print() methods weren't being called is because of the Unity environment. The AdMob plugin is intentionally designed to be non-functional while running it directly in Unity; thus, any ad-related calls will simply be replaced by dummy ones (as we can see in via the Unity console). You will have to build the sample project and run it in Android or iOS in order to replicate the intended behavior of the script.
  • I think this is also causing the Banner to display immediately after loading, even if I don’t call the bannerview.Show() method.
    • I believe that the ad that is "displaying" immediately is actually the sample rewarded ad. For reference, you will see a call to CreateAndLoadRewardedAd() inside the Start() function of the sample script.
  • I’m going to attach a picture of what my unity console SHOULD be showing according to google examples compared to what IS currently showing. As you will see, I never receive the “Event Received” message. 
    • As with the first concern above, this is due to the fact that any ad-related calls are replaced with dummy ones while running the app directly inside Unity. You technically received all those calls, but the script you are seeing isn't actually the one responding to the calls. This is intentional.


As has been discussed, you may try building the app and running it on a mobile device to verify the correctness of the sample project. Feel free to send a copy of the sample project (via Reply privately to author) if the issue still persists thereafter.

I hope this helps.



Regards,
Ziv Yves Sanchez
Mobile Ads SDK Team



ref:_00D1U1174p._5001UKM8u7:ref

Mobile Ads SDK Forum Advisor Prod

unread,
Oct 6, 2019, 10:22:29 PM10/6/19
to lunet...@gmail.com, google-adm...@googlegroups.com

Hi there,

Thank you for clarifying your concern on the banner ads.

Showing the ad immediately after it successfully loads (via LoadAd()) is an intentional design as well, since banner ads are allowed to unobtrusively show up at any time in an app (as compared to interstitial and rewarded ads). That being said, you have three options on how to approach the timing of the showing of banner ads:

  • Simply call LoadAd() only on sections when you actually want the banner ad to actually display, or
  • Hide() the banner ad before loading it, then alternate between Show() and Hide() in order to control its appearance on your app.
  • In case of Scene changes, you will have to initialize and Destroy() the banner ad instead if its parent GameObject isn't persistent (that is, if it's not using the DontDestroyOnLoad() function).


Let me know if this helps.



Regards,
Ziv Yves Sanchez
Mobile Ads SDK Team



ref:_00D1U1174p._5001UKM8u7:ref
Reply all
Reply to author
Forward
0 new messages