Initializing the SDK in Unity

To initialize the SDK, you must reference your project’s Game ID for the appropriate platform. You can locate the ID from the Monetization dashboard by selecting Project > Project Settings in the secondary navigation bar and scrolling to the Game IDs section.

In your game script header, include the UnityEngine.Advertisements namespace. Initialize the SDK early in the game’s run-time life cycle, preferably at launch, using the Initialize function. In SDK versions 3.7.0 and higher, you can use IUnityAdsInitializationListener callbacks to receive a notification when initialization is complete, or receive the details when an error occurs.

Copy
using UnityEngine;
using UnityEngine.Advertisements;
 
public class AdsInitializer : MonoBehaviour, IUnityAdsInitializationListener
{
    [SerializeField] string _androidGameId;
    [SerializeField] string _iOSGameId;
    [SerializeField] bool _testMode = true;
    private string _gameId;
 
    void Awake()
    {
        InitializeAds();
    }
 
    public void InitializeAds()
    {
        _gameId = (Application.platform == RuntimePlatform.IPhonePlayer)
            ? _iOSGameId
            : _androidGameId;
        Advertisement.Initialize(_gameId, _testMode, this);
    }
 
    public void OnInitializationComplete()
    {
        Debug.Log("Unity Ads initialization complete.");
    }
 
    public void OnInitializationFailed(UnityAdsInitializationError error, string message)
    {
        Debug.Log($"Unity Ads Initialization Failed: {error.ToString()} - {message}");
    }
}

Next steps: See documentation on implementing basic ads to continue your integration.