Initialize the SDK in Unity
Initialize the Unity Ads SDK with your Game ID to enable monetization and access Unity Ads public APIs in your Unity project.
Read time 1 minuteLast updated 4 hours ago
To initialize the SDK, you must reference your project's Game ID for the appropriate platform. You can locate the Game ID from the Unity Ads Monetization dashboard by selecting the Monetization suite, navigating to your current project, then Settings in the secondary navigation bar, and scrolling to the Game IDs section.
In your game script header, include the
UnityEngine.Advertisements
Initialize
IUnityAdsInitializationListener
Next steps: To continue your integration, refer to the Implement interstitial ads in Unity documentation.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() { #if UNITY_IOS _gameId = _iOSGameId; #elif UNITY_ANDROID _gameId = _androidGameId; #elif UNITY_EDITOR _gameId = _androidGameId; //Only for testing the functionality in the Editor #endif if (!Advertisement.isInitialized && Advertisement.isSupported) { 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}"); } }