IUnityAdsListener Is not getting callbacks

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Advertisements;
[RequireComponent(typeof(Button))]
public class UnityAdsController : MonoBehaviour,IUnityAdsListener
{
#if UNITY_IOS
    private string gameId = "1111111";
#elif UNITY_ANDROID
    private string gameId = "1111111";
#endif

    Button myButton;
    public string myPlacementId = "rewardedVideo";
    void Start()
    {
        myButton = GetComponent<Button>();
        // Set interactivity to be dependent on the Placement’s status:
        // myButton.interactable = Advertisement.IsReady(myPlacementId);

        // Map the ShowRewardedVideo function to the button’s click listener:
        if (myButton) myButton.onClick.AddListener(ShowRewardedVideo);
      
        // Initialize the Ads listener and service:
        Advertisement.AddListener(this);
        Advertisement.Initialize(gameId, true);

    }

    // Implement a function for showing a rewarded video ad:
    void ShowRewardedVideo()
    {
        Advertisement.Show(myPlacementId);
    }

 
// Implement IUnityAdsListener interface methods:
public void OnUnityAdsReady(string placementId)
    {
        // If the ready Placement is rewarded, activate the button:
        if (placementId == myPlacementId)
        {
            myButton.interactable = true;
        }
        Debug.Log("INITIALIZED");
    }
    public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
    {
        // Define conditional logic for each ad completion status:
        if (showResult == ShowResult.Finished)
        {
            Debug.LogWarning("Finished");
        }
        else if (showResult == ShowResult.Skipped)
        {
            // Do not reward the user for skipping the ad.
        }
        else if (showResult == ShowResult.Failed)
        {
            Debug.LogWarning("");
        }
    }

    public void OnUnityAdsDidError(string message)
    {
        // Log the error.
    }

    public void OnUnityAdsDidStart(string placementId)
    {
        // Optional actions to take when the end-users triggers an ad.
    }
}

I’m using this code. I can see the ads but i cannot get any Callbacks. Am I doing something wrong here? Or IUnityAdsListener is not working?

1 Like

Exactly like me, but sometimes is work in editor!
What i tried
Platform : Android 6 and above & IOS 12 & above

1 -Install Unity Ads from assetstore store Or from package manger in unity 2019.2 is work
but in unity 2018 sometimes is work in editor not mobile

2- Turn off Ads service is not helpful “enable built in etc”.

I don’t know what is problem my code exactly like "
Rewarded video ad buttons
" Unity developer integration guides

Logcat

12-15 21:53:27.479 31365-31374/? I/art: Background sticky concurrent mark sweep GC freed 292956(14MB) AllocSpace objects, 11(276KB) LOS objects, 32% free, 31MB/46MB, paused 5.045ms total 189.514ms
12-15 21:53:29.730 1186-1227/? I/UnityAds: com.unity3d.services.ads.UnityAdsImplementation.show() (line:6) :: Unity Ads opening new ad unit for placement VDREWARDEDV3
12-15 21:53:29.778 1186-1471/? I/UnityAds: com.unity3d.services.core.api.Sdk.logInfo() (line:1) :: Opening performance ad unit with orientation PORTRAIT, hardware acceleration enabled
  
    --------- beginning of system
12-15 21:53:29.796 781-1894/? I/ActivityManager: START u0 {flg=0x10010000 cmp=com.abualamrin.humantest/com.unity3d.services.ads.adunit.AdUnitActivity (has extras)} from uid 10333 on display 0
12-15 21:53:29.906 781-799/? I/ActivityManager: Displayed com.abualamrin.humantest/com.unity3d.services.ads.adunit.AdUnitActivity: +90ms
12-15 21:53:29.907 1618-1618/? I/Keyboard.Facilitator: onFinishInput()
12-15 21:53:29.925 781-1669/? I/MediaFocusControl:  AudioFocus  requestAudioFocus() from android.media.AudioManager@43a0dc req=1flags=0x0
12-15 21:53:29.929 201-2425/? D/NuPlayer: onSetVideoSurface(0xb4845f00, no video decoder)
12-15 21:53:29.969 201-2425/? D/NuPlayerDriver: notifyListener_l(0xb28e0660), (5, 320, 180)
12-15 21:53:29.970 201-2425/? D/NuPlayerDriver: notifyListener_l(0xb28e0660), (1, 0, 0)
12-15 21:53:29.993 1186-1186/? D/MediaPlayer: getMetadata
12-15 21:53:30.014 201-26475/? D/NuPlayerDriver: start(0xb28e0660), state is 4, eos is 0
12-15 21:53:30.014 201-2425/? I/GenericSource: start
12-15 21:53:30.102 201-2441/? I/OMX-VDEC-1080P: component_init: OMX.qcom.video.decoder.avc : fd=19
12-15 21:53:30.103 201-2441/? I/OMX-VDEC-1080P: Capabilities: driver_name = msm_vidc_driver, card = msm_vdec_8974, bus_info = , version = 1, capabilities = 4003000
12-15 21:53:30.109 201-2441/? I/OMX-VDEC-1080P: omx_vdec::component_init() success : fd=19
12-15 21:53:30.111 201-2438/? I/MediaCodec: [OMX.qcom.video.decoder.avc] setting surface generation to 205839
12-15 21:53:30.112 201-2441/? E/OMX-VDEC-1080P: Extension: OMX.google.android.index.storeANWBufferInMetadata not implemented
12-15 21:53:30.113 201-2440/? E/OMXNodeInstance: setConfig(61:google.aac.decoder, ConfigPriority(0x6f800002)) ERROR: Undefined(0x80001001)
12-15 21:53:30.113 201-2440/? I/ACodec: codec does not support config priority (err -2147483648)
12-15 21:53:30.113 201-2440/? I/MediaCodec: MediaCodec will operate in async mode
12-15 21:53:30.116 201-2453/? I/SoftAAC2: Reconfiguring decoder: 0->44100 Hz, 0->2 channels
12-15 21:53:30.117 201-2438/? I/MediaCodec: MediaCodec will operate in async mode
12-15 21:53:30.136 201-2441/? D/SurfaceUtils: set up nativeWindow 0xb4845f08 for 320x180, color 0x7fa30c04, rotation 0, usage 0x42002900
12-15 21:53:30.147 201-814/? D/audio_hw_primary: out_set_parameters: enter: usecase(1: low-latency-playback) kvpairs: routing=2
12-15 21:53:30.148 201-2425/? D/NuPlayerDriver: notifyListener_l(0xb28e0660), (6, 0, 0)
12-15 21:53:30.154 201-2441/? D/SurfaceUtils: set up nativeWindow 0xb4845f08 for 320x192, color 0x7fa30c04, rotation 0, usage 0x42002900
12-15 21:53:30.155 31399-24752/? I/Checkin: [EventLogChimeraService] Opted in for usage reporting: true
12-15 21:53:30.155 31399-24752/? I/Checkin: [EventLogChimeraService] Aggregate from 1576437231608 (log), 1576437231608 (data)
12-15 21:53:30.168 201-2425/? D/NuPlayerDriver: notifyListener_l(0xb28e0660), (5, 320, 180)
12-15 21:53:30.168 201-2425/? D/NuPlayerDriver: notifyListener_l(0xb28e0660), (200, 3, 0)
12-15 21:53:30.168 1186-1203/? W/MediaPlayer: info/warning (3, 0)
12-15 21:53:30.222 201-814/? D/AudioFlinger: mixer(0xb4100000) throttle end: throttle time(11)
12-15 21:53:30.310 1186-1471/? I/UnityAds: com.unity3d.services.core.api.Sdk.logInfo() (line:1) :: Unity Ads event: sending start event to https://impact.applifier.com/events/v2/video/video_start/1773727/000000000000000000000000
12-15 21:53:30.352 781-1686/? W/DropBoxManagerService: Dropping: event_log (61 > 0 bytes)
12-15 21:53:30.358 781-1669/? W/DropBoxManagerService: Dropping: event_data (39 > 0 bytes)
12-15 21:53:30.370 31399-24752/? I/Checkin: [ServiceDumpSys] dumping service [account]
12-15 21:53:30.380 781-1670/? W/DropBoxManagerService: Dropping: dumpsys:account (234 > 0 bytes)
12-15 21:53:30.612 31365-31365/? W/ChimeraUtils: Non Chimera context
12-15 21:53:30.634 31365-2462/? I/aokb: Removed 0 invalid users [CONTEXT service_id=51 ]
12-15 21:53:30.964 31365-2462/? W/Conscrypt: Could not set socket write timeout: java.net.SocketException: Socket closed
12-15 21:53:30.974 31365-2462/? W/Conscrypt:     at com.google.android.gms.org.conscrypt.Platform.setSocketWriteTimeout(:com.google.android.gms@19831018@19.8.31 (040308-284611645):2)
12-15 21:53:30.974 31365-2462/? W/Conscrypt:     at com.google.android.gms.org.conscrypt.ConscryptFileDescriptorSocket.setSoWriteTimeout(:com.google.android.gms@19831018@19.8.31 (040308-284611645):2)
12-15 21:53:31.080 781-1669/? W/DropBoxManagerService: Dropping: exp_det_cert_pin_failure (10 > 0 bytes)
12-15 21:53:31.138 31365-2462/? W/Conscrypt: Could not set socket write timeout: java.net.SocketException: Socket closed
12-15 21:53:31.138 31365-2462/? W/Conscrypt:     at com.google.android.gms.org.conscrypt.Platform.setSocketWriteTimeout(:com.google.android.gms@19831018@19.8.31 (040308-284611645):2)
12-15 21:53:31.138 31365-2462/? W/Conscrypt:     at com.google.android.gms.org.conscrypt.ConscryptFileDescriptorSocket.setSoWriteTimeout(:com.google.android.gms@19831018@19.8.31 (040308-284611645):2)
12-15 21:53:32.171 31365-2462/? I/aojp: Scheduling adaptive one off task with window [14400, 604800] in seconds [CONTEXT service_id=51 ]
12-15 21:53:32.296 1186-1471/? I/UnityAds: com.unity3d.services.core.api.Sdk.logInfo() (line:1) :: Unity Ads event: sending first_quartile event to https://impact.applifier.com/events/v2/video/first_quartile/1773727/000000000000000000000000
12-15 21:53:34.602 1186-1471/? I/UnityAds: com.unity3d.services.core.api.Sdk.logInfo() (line:1) :: Unity Ads event: sending midpoint event to https://impact.applifier.com/events/v2/video/midpoint/1773727/000000000000000000000000
12-15 21:53:35.847 1186-1471/? I/UnityAds: com.unity3d.services.core.api.Sdk.logInfo() (line:1) :: Requesting ad plan from https://auction.unityads.unity3d.com/v4/test/games/1773727/requests?advertisingTrackingId=3a249062-21fc-49bb-93dd-df25f2b2584d&limitAdTracking=true&deviceModel=Nexus%205&platform=android&sdkVersion=3400&stores=google&deviceMake=LGE&screenSize=268435794&screenDensity=480&apiLevel=23&test=true&screenWidth=1080&screenHeight=1776&connectionType=wifi&networkType=0
12-15 21:53:36.557 1186-1471/? I/UnityAds: com.unity3d.services.core.api.Sdk.logInfo() (line:1) :: Unity Ads event: sending third_quartile event to https://impact.applifier.com/events/v2/video/third_quartile/1773727/000000000000000000000000
12-15 21:53:36.773 1186-1471/? I/UnityAds: com.unity3d.services.core.api.Sdk.logInfo() (line:1) :: AdPlan received with 1 campaigns and refreshDelay 0
12-15 21:53:38.005 201-2439/? I/NuPlayerDecoder: [audio] saw output EOS
12-15 21:53:38.304 201-2437/? I/NuPlayerDecoder: [video] saw output EOS
12-15 21:53:38.485 201-2425/? D/NuPlayerDriver: notifyListener_l(0xb28e0660), (2, 0, 0)
12-15 21:53:38.516 201-1041/? D/NuPlayerDriver: stop(0xb28e0660)
12-15 21:53:38.516 201-1041/? D/NuPlayerDriver: notifyListener_l(0xb28e0660), (8, 0, 0)
12-15 21:53:38.517 201-1040/? D/NuPlayerDriver: reset(0xb28e0660)
12-15 21:53:38.521 201-2425/? W/AMessage: failed to post message as target looper for handler 0 is gone.
12-15 21:53:38.540 201-2441/? I/OMX-VDEC-1080P: omx_vdec::component_deinit() complete
12-15 21:53:38.564 201-2441/? I/OMX-VDEC-1080P: Exit OMX vdec Destructor: fd=19
12-15 21:53:38.567 201-2425/? W/AMessage: failed to post message as target looper for handler 0 is gone.
12-15 21:53:38.569 201-2425/? D/NuPlayerDriver: notifyResetComplete(0xb28e0660)
12-15 21:53:38.571 781-1893/? I/MediaFocusControl:  AudioFocus  abandonAudioFocus() from android.media.AudioManager@43a0dc
12-15 21:53:38.579 1186-1471/? I/UnityAds: com.unity3d.services.core.api.Sdk.logInfo() (line:1) :: Unity Ads event: sending view event to https://impact.applifier.com/events/v2/video/video_end/1773727/000000000000000000000000
12-15 21:53:38.586 1186-1186/? W/MediaPlayer: mediaplayer went away with unhandled events
12-15 21:53:38.595 1618-1618/? I/Keyboard.Facilitator: onFinishInput()
12-15 21:53:39.551 1186-1186/? I/chromium: [INFO:CONSOLE(22848)] "Uncaught (in promise) Experiment session not started.", source: file:///storage/emulated/0/Android/data/com.abualamrin.humantest/cache/UnityAdsCache/UnityAdsWebApp.html?platform=android&origin=https%3A%2F%2Fwebview.unityads.unity3d.com%2Fwebview%2F3.4.0%2F78d2436ae72e107aef173839f2d1c75b335ae789%2Frelease%2Findex.html&version=78d2436ae72e107aef173839f2d1c75b335ae789 (22848)
12-15 21:53:39.607 1186-1471/? I/UnityAds: com.unity3d.services.core.api.Sdk.logInfo() (line:1) :: Closing Unity Ads ad unit
12-15 21:53:39.669 1618-1618/? I/Keyboard.Facilitator: onFinishInput()
12-15 21:53:39.748 201-814/? D/audio_hw_primary: out_set_parameters: enter: usecase(1: low-latency-playback) kvpairs: routing=2
12-15 21:53:39.781 201-814/? D/AudioFlinger: mixer(0xb4100000) throttle end: throttle time(7)
12-15 21:53:40.485 211-294/? I/ThermalEngine: TM Id 'SKIN_THERMAL_management_1' Sensor 'xo_therm_pu2' - alarm raised 2 at 42.0 degC
12-15 21:53:40.485 211-294/? I/ThermalEngine: ACTION: CPU - Setting CPU[0] to 1574400
12-15 21:53:40.485 211-294/? I/ThermalEngine: ACTION: CPU - Setting CPU[1] to 1574400
12-15 21:53:40.485 211-294/? I/ThermalEngine: ACTION: CPU - Setting CPU[2] to 1574400
12-15 21:53:40.485 211-294/? I/ThermalEngine: ACTION: CPU - Setting CPU[3] to 1574400
12-15 21:53:40.486 211-294/? I/ThermalEngine: ACTION: LCD - Setting max LCD brightness to 204
12-15 21:53:40.486 211-294/? I/ThermalEngine: Setting curr LCD brightness to 255

Man this code is work but in editor say “[deprecated] class UnityEngine.Monetization.Monetization”
Look if this work does matter, when unity team make good update for Ads and unity 2019 without pink screen and fix 2018 we make update for those libraries.
Note: This code not from me this code from https://unityads.unity3d.com/help/unity/integration-guide-unity

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Monetization;

[RequireComponent (typeof (Button))]
public class UnityAdsButton : MonoBehaviour {

    public string placementId = "rewardedVideo";
    private Button adButton;

#if UNITY_IOS
   private string gameId = "111111";
#elif UNITY_ANDROID
    private string gameId = "11111";
#endif

    void Start () {
        adButton = GetComponent<Button> ();
        if (adButton) {
            adButton.onClick.AddListener (ShowAd);
        }

        if (Monetization.isSupported) {
            Monetization.Initialize (gameId, true);
        }
    }

    void Update () {
        if (adButton) {
            adButton.interactable = Monetization.IsReady (placementId);
        }
    }

    void ShowAd () {
        ShowAdCallbacks options = new ShowAdCallbacks ();
        options.finishCallback = HandleShowResult;
        ShowAdPlacementContent ad = Monetization.GetPlacementContent (placementId) as ShowAdPlacementContent;
        ad.Show (options);
    }

    void HandleShowResult (ShowResult result) {
        if (result == ShowResult.Finished) {
            // Reward the player
        } else if (result == ShowResult.Skipped) {
            Debug.LogWarning ("The player skipped the video - DO NOT REWARD!");
        } else if (result == ShowResult.Failed) {
            Debug.LogError ("Video failed to show");
        }
    }
}

Hi,

Thanks for reporting. I checked with the team, and unfortunately there is an issue with SDK 3.4 on Android:

2 Likes

I also confirm this bug.
It works only once in the Editor, and then Listener stops getting info. But if you close Unity, and reopen it, then it will work again, but of course only in first Play session.
In android devices, it doesn’t work even for the first time.
Unity 2018.3.4f1 , Android Platform, Unity Monetization v3.4.0 (downloaded from asset store)

Can you share SDK 3.3.0 (unitypackage)? I can’t find any link to it.

I verified with Unity 2018.4.14f1, that you can use Package Manager window to use a previous version of Ads SDK

Would that work for you?

Yeap, I forgot about Package Manager, thanks)

I have 2 questions:
1) Is the 3.3.1 works correct? Or it is better to install 3.3.0?

2) What is the most correct way to remove 3.4?
Will just deleting the folder “UnityAds” and then adding 3.3 from Package Manager lead to some bugs?
Or do I have to find and delete all the files from these folders one by one too?
Editor-Resources
Plugins-Android-iOS

I believe 3.3.1 should work. I haven’t had time to try myself, but as far as I know issue exists only in 3.4.0

If you have installed from Asset Store, you should also remove UnityAds files under Plugins folder as well.

/Rasmus

1 Like

Having the same problem but using Unity Ads from the asset store. Should I use the version from the package manager?

I can only see versions 2.0.8 and 3.4.1 there. Does 3.4.1 have the fix?

3.4.1 is even worse. you don’t get any events triggered even in editor

…OK so is there a solution?

@bartofzo
Thanks for reporting this issue. We’ll need some more information:

Which version of Unity are you using?
Can you provide the script you are using to test the callbacks?
Can you provide the manifest.json file in your Packages folder?

Did you click on “All Versions” ?

Unity 2019.*

Unity 2018.*

2019.2.16f1

I was using the version from the asset store so I can’t find a manifest.json

Regarding the script, it is almost exactly the same as the example in the documentation. And I have confirmed it works on an iOS build, so I’m assuming my code is correct.

No I didn’t. Thanks! I’ll try this out later today.

@bartofzo It sounds like your having an issue with callbacks on device. Please note that in 3.4.0 we had an issue with callbacks on android devices and this was fixed in 3.4.1. You will find this new version on the asset store and in package manager. If you are still having issues after updating to 3.4.1 please start a new issue with your specific details including a repro script/project if possible. Thanks

Same issue, Unity 2019.2.14f1. Started on ads 3.4.1 and tried 3.4.0, 3.3.1, 3.3.0. All no callbacks being fired. Ads work in other methods but the callbacks are just not being fired. Is there any special cache folders that need to be deleted to make downgrading work?

1 Like

Was able to fix this by upgrading to Ads 3.4.2 (from 3.4.0) and my project to Unity 2019.3.0f6 (from 2019.2.3). Just upgrading to 3.4.2 didn’t do it: I had to upgrade the project as well. Perhaps anecdotal, but hopefully helps others out.

Any news on this?
>> Unity 2020.1.0a24
Same problem here.
Below log from android device connected to the Unity Console.
Got not callback from listeners at all.
5533372--568678--Screen Shot 2020-02-28 at 22.48.51.png

Also double checking the documentation to see if any update and from the Testing section, somethings goes wrong :

I click on the Developer Dashboard blue link, then Settings, but no Project Settings there.
It’s because I remember playing with it the last month and there was the TestMode switch as mentioned…

Wrong URL from the doc? Something wrong on your side?

EDIT :

Alright documentation should be :
2. Select Projects to access to the Project List view : Select your project.
3. Select Settings > Project Settings from the left navigation bar.
etc…