UnityAds stopped initializing after adding code about the Google Family policy update

Unity: 2021.2.5f1
Unity Ads (Advertisement): 3.7.5 (August 02, 2021)

UnityAds stopped initializing after adding code about the Google Family policy update
(added in code OnInitializationComplete())

MetaData metaData = new MetaData("privacy");
metaData.Set("mode", "mixed"); // This is a mixed audience game.
Advertisement.SetMetaData(metaData);

AdsInitializer.cs (Initializing of Unity Ads)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Advertisements;

public class AdsInitializer : MonoBehaviour, IUnityAdsInitializationListener
{
    [SerializeField] private string _androidGameId = "39XXXXX";
    [SerializeField] private string _iOSGameId = "39XXXXX";
    private string _gameId;
    //
    private static GameObject playerInstance;

    void Awake()
    {
        //
            DontDestroyOnLoad(this);
            if (playerInstance == null)
            {
                playerInstance = gameObject;
            }
            else
            {
                Destroy(gameObject);
            }    
        //
        InitializeAds();
    }

    public void InitializeAds()
    {
        _gameId = (Application.platform == RuntimePlatform.IPhonePlayer)
            ? _iOSGameId
            : _androidGameId;

        //   Advertisement.Initialize(_gameId, _testMode);
        Advertisement.Initialize(_gameId, false);
      
    }

    public void OnInitializationComplete()
    {
        Debug.Log("Unity Ads initialization complete.");
        //
#if UNITY_ANDROID
        //If your game is directed at mixed audiences, use this code to inform Unity Ads when users should not receive personalized ads
        //for Android
        MetaData metaData = new MetaData("privacy");
        metaData.Set("mode", "mixed"); // This is a mixed audience game.
        Advertisement.SetMetaData(metaData);
#endif

    }

    public void OnInitializationFailed(UnityAdsInitializationError error, string message)
    {
        Debug.Log($"Unity Ads Initialization Failed: {error.ToString()} - {message}");
    }
}

On Project Settings/Ads/Test mode
7983180--1025295--image002.jpg

How to solve this troubles with Unity Ads?

Hi,

It works for me like this:

 [SerializeField] string UnityAdsID;
    [SerializeField] string UnityAdsID_IOS;
    [SerializeField] bool _testMode = false;
    [SerializeField] bool _enablePerPlacementMode = false;

    private string _gameId;


void Awake()
    {  
       InitUnityAds();
    }

private void InitUnityAds()
    {
        _gameId = (Application.platform == RuntimePlatform.IPhonePlayer)
            ? UnityAdsID_IOS
            : UnityAdsID;

        if (Advertisement.isInitialized == false)
        {
            Advertisement.Initialize(_gameId, _testMode, _enablePerPlacementMode, this);
        }
    }

public void OnInitializationComplete()
    {
        Debug.Log("Unity Ads initialization complete.");
#if UNITY_ANDROID
        //If your game is directed at mixed audiences, use this code to inform Unity Ads when users should not receive personalized ads
        //for Android
        MetaData metaData = new MetaData("privacy");
        metaData.Set("mode", "mixed"); // This is a mixed audience game.
        Advertisement.SetMetaData(metaData);
#endif
    }

    public void OnInitializationFailed(UnityAdsInitializationError error, string message)
    {
        Debug.Log($"Unity Ads Initialization Failed: {error.ToString()} - {message}");
    }

Hello!
Small question.

Why didn’t you add “nonbehavioral”?
MetaData userMetaData = new MetaData(“user”);
userMetaData.Set(“nonbehavioral”, “true”);
Advertisement.SetMetaData(userMetaData);

And in another thread I read that the metadata needs to be added before the initialization.

Thanks in advance

In next step, I add the metadata prior to initialization…

void Awake()
    {           
     #if UNITY_ANDROID
        //If your game is directed at mixed audiences, use this code to inform Unity Ads when users should not receive personalized ads
        //for Android
        MetaData metaData = new MetaData("privacy");
        metaData.Set("mode", "mixed"); // This is a mixed audience game.
        Advertisement.SetMetaData(metaData);
     #endif

        //
        InitializeAds();
    }

And Unity Ads is not initialized …
7986255--1025916--adb2.png

1 Like

Try copy / paste my code works for you?

I’m also not entirely sure how to do it, but initialization works for me.
https://discussions.unity.com/t/875329

1 Like

I set in code

void Awake()
    { 
  //
#if UNITY_ANDROID
        //If your game is directed at mixed audiences, use this code to inform Unity Ads when users should not receive personalized ads
        //for Android
        /*
        MetaData metaData = new MetaData("privacy");
        metaData.Set("mode", "mixed"); // This is a mixed audience game.
        Advertisement.SetMetaData(metaData);
        */
        MetaData userMetaData = new MetaData("user");
        userMetaData.Set("nonbehavioral", "true");
        Advertisement.SetMetaData(userMetaData);
#endif

        //
        InitializeAds();
    }

Initialization is not worked

7989249--1026555--adb3.png

It looks like the app is missing the initialize method, did you obfuscate the code or delete any files? Might be worth trying to re-import the Ads SDK or start a new project.

Hello!

A quick question.

If the flag “mixed” is set to true, then before the start of the game need to make a menu of age selection? To determine whether a child or an adult is playing? And after set the value for “nonbehavioral” to “true” or “false”. I understand everything correctly?

Thanks in advance

Solved! It’s bug of Unity Ads!.. I deleted UnityAds package from project, clean Temp in Project, reload Unity,
install Unity Ads again and It’s worked!