Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question Go to the background with the home button while watching an ad

Discussion in 'Unity Mediation' started by skfldao, Mar 17, 2022.

  1. skfldao

    skfldao

    Joined:
    Jul 28, 2019
    Posts:
    18
    This is the process I am testing.
    1. Move to the background with the Home button while watching advertisements.
    2. Go back to the app
    3. The ad is skipped

    When an advertisement is skipped by the above process, the user can't get rewarded.
    However, only the first time a failure response is received and the function registered as
    OnFailedShow
    is executed. 2nd and 3rd are not executed.

    Can I get a one time failure response or is it taking a long time?

    I use the same code as written in Mediation - Code Generator.
    Code (CSharp):
    1. using System;
    2. using Unity.Services.Core;
    3. using Unity.Services.Mediation;
    4. using UnityEngine;
    5.  
    6. namespace Unity.Example
    7. {
    8.     public class InterstitialAdExample
    9.     {
    10.         IInterstitialAd ad;
    11.         string adUnitId = "/*ad unit id*/";
    12.         string gameId = "/*android game id*/";
    13.  
    14.         public async void InitServices()
    15.         {
    16.             try
    17.             {
    18.                 InitializationOptions initializationOptions = new InitializationOptions();
    19.                 initializationOptions.SetGameId(gameId);
    20.                 await UnityServices.InitializeAsync(initializationOptions);
    21.  
    22.                 InitializationComplete();
    23.             }
    24.             catch (Exception e)
    25.             {
    26.                 InitializationFailed(e);
    27.             }
    28.         }
    29.  
    30.         public void SetupAd()
    31.         {
    32.             //Create
    33.             ad = MediationService.Instance.CreateInterstitialAd(adUnitId);
    34.  
    35.             //Subscribe to events
    36.             ad.OnLoaded += AdLoaded;
    37.             ad.OnFailedLoad += AdFailedLoad;
    38.  
    39.             ad.OnShowed += AdShown;
    40.             ad.OnFailedShow += AdFailedShow;
    41.             ad.OnClosed += AdClosed;
    42.             ad.OnClicked += AdClicked;
    43.        
    44.             // Impression Event
    45.             MediationService.Instance.ImpressionEventPublisher.OnImpression += ImpressionEvent;
    46.         }
    47.  
    48.         public void ShowAd()
    49.         {
    50.             if (ad.AdState == AdState.Loaded)
    51.             {
    52.                 ad.Show();
    53.             }
    54.         }
    55.  
    56.         void InitializationComplete()
    57.         {
    58.             SetupAd();
    59.             ad.Load();
    60.         }
    61.  
    62.         void InitializationFailed(Exception e)
    63.         {
    64.             Debug.Log("Initialization Failed: " + e.Message);
    65.         }
    66.  
    67.         void AdLoaded(object sender, EventArgs args)
    68.         {
    69.             Debug.Log("Ad loaded");
    70.         }
    71.  
    72.         void AdFailedLoad(object sender, LoadErrorEventArgs args)
    73.         {
    74.             Debug.Log("Failed to load ad");
    75.             Debug.Log(args.Message);
    76.         }
    77.  
    78.         void AdShown(object sender, EventArgs args)
    79.         {
    80.             Debug.Log("Ad shown!");
    81.         }
    82.  
    83.         void AdClosed(object sender, EventArgs e)
    84.         {
    85.             // Pre-load the next ad
    86.             ad.Load();
    87.             Debug.Log("Ad has closed");
    88.             // Execute logic after an ad has been closed.
    89.         }
    90.  
    91.         void AdClicked(object sender, EventArgs e)
    92.         {
    93.             Debug.Log("Ad has been clicked");
    94.             // Execute logic after an ad has been clicked.
    95.         }
    96.  
    97.         void AdFailedShow(object sender, ShowErrorEventArgs args)
    98.         {
    99.             Debug.Log(args.Message);
    100.         }
    101.  
    102.         void ImpressionEvent(object sender, ImpressionEventArgs args)
    103.         {
    104.             var impressionData = args.ImpressionData != null ? JsonUtility.ToJson(args.ImpressionData, true) : "null";
    105.             Debug.Log("Impression event from ad unit id " + args.AdUnitId + " " + impressionData);
    106.         }
    107.    
    108.     }
    109. }
     
  2. Unity-Boon

    Unity-Boon

    Unity Technologies

    Joined:
    Jan 18, 2017
    Posts:
    105
    @skfldao Can you provide some additional information for us?

    1. Which device you are using for testing and what is the OS version?
    2. Which version of Unity Mediation SDK are you using?
    3. Is it happen to the ads from specific ads networks or do all the ads have this issue?
     
  3. skfldao

    skfldao

    Joined:
    Jul 28, 2019
    Posts:
    18
    1. I'm using LD player, not a real device. The device set in LD Player is Galaxy Note9. OS is Android 7.1.2.
    2. I'm using 0.4.0-preview.1 version.
    3. When I posted the question, only Unity Ads were registered in Ad Source. So I checked that it happening in Unity Ads. But I haven't checked yet to see it in other ads. I recently added AppLovin and will be testing it tomorrow. If it also occurs in AppLovin, I will add an additional comment.
     
    Last edited: Mar 23, 2022
  4. skfldao

    skfldao

    Joined:
    Jul 28, 2019
    Posts:
    18
    The same happens in AppLovin.
     
  5. Unity-Boon

    Unity-Boon

    Unity Technologies

    Joined:
    Jan 18, 2017
    Posts:
    105
    @skfldao

    Can you test it on the real device and see if it still happen?
    Can you send us the full device log when the error happens for us to do some investigation? You could send it to unityads-support@unity3d.com if you prefer not to attach it here.

    Thanks.
     
  6. skfldao

    skfldao

    Joined:
    Jul 28, 2019
    Posts:
    18
    I've confirmed that it doesn't happen on iPhones among real devices.
    I'm trying to check my Android device, but do I need to send the device log instead of the Unity Debug Log?
    If yes, how can I check the device log?