Unity Admob Interstitial Ads Tutorial Admob Interstitial Ads Unity Tutorial

Unity Admob Interstitial Ads Tutorial | Admob Interstitial Ads Unity Tutorial

Unity Admob Interstitial Ads Tutorial | Admob Interstitial Ads Unity Tutorial :- This tutorial offers a step-by-step guide to integrating AdMob’s interstitial ads into your Unity application. Interstitial ads are engaging, full-screen ads that appear between game levels or at key moments, helping you generate revenue without disrupting gameplay. You’ll start by setting up AdMob in your Unity project, configuring ad units, and then learn how to code the logic to load and display interstitial ads at strategic points. The tutorial emphasizes best practices for maintaining a positive user experience while optimizing your ad revenue. Ideal for Unity developers seeking to enhance their monetization strategy with effective ad placements.

CONTACT US TO ADD 10 AD NETWORKS TO YOUR UNITY PROJECT – CHARGES APPLY

DOWNLOAD ADMOB PLUGIN

FULL ADMOB INTERSTITIAL ADS SCRIPT

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds;
using GoogleMobileAds.Api;
using System;

public class AdmobInterstitial : MonoBehaviour
{

    private InterstitialAd interstitialAd;
    public string interstitialId = "";


    public static AdmobInterstitial instance;


    // Start is called before the first frame update
    void Start()
    {

        MobileAds.Initialize((InitializationStatus initStatus) =>
        {
            // This callback is called once the MobileAds SDK is initialized.
            LoadInterstitialAd();
        });

    }

    void Awake()
    {

        instance = this;

    }


    public void LoadInterstitialAd()
    {
        // Clean up the old ad before loading a new one.
        if (interstitialAd != null)
        {
            interstitialAd.Destroy();
            interstitialAd = null;
        }

        Debug.Log("Loading the interstitial ad.");

        // create our request used to load the ad.
        var adRequest = new AdRequest();

        // send the request to load the ad.
        InterstitialAd.Load(interstitialId, adRequest,
            (InterstitialAd ad, LoadAdError error) =>
            {
                // if error is not null, the load request failed.
                if (error != null || ad == null)
                {
                    Debug.LogError("interstitial ad failed to load an ad " +
                                   "with error : " + error);
                    return;
                }

                Debug.Log("Interstitial ad loaded with response : "
                          + ad.GetResponseInfo());

                interstitialAd = ad;
                RegisterEventHandlers(interstitialAd);
            });
    }

    public void ShowInterstitialAd()
    {
        if (interstitialAd != null && interstitialAd.CanShowAd())
        {
            Debug.Log("Showing interstitial ad.");
            interstitialAd.Show();
        }
        else
        {
            Debug.LogError("Interstitial ad is not ready yet.");
        }
    }

    private void RegisterEventHandlers(InterstitialAd interstitialAd)
    {
        // Raised when the ad is estimated to have earned money.
        interstitialAd.OnAdPaid += (AdValue adValue) =>
        {
            Debug.Log(String.Format("Interstitial ad paid {0} {1}.",
                adValue.Value,
                adValue.CurrencyCode));
        };
        // Raised when an impression is recorded for an ad.
        interstitialAd.OnAdImpressionRecorded += () =>
        {
            Debug.Log("Interstitial ad recorded an impression.");
        };
        // Raised when a click is recorded for an ad.
        interstitialAd.OnAdClicked += () =>
        {
            Debug.Log("Interstitial ad was clicked.");
        };
        // Raised when an ad opened full screen content.
        interstitialAd.OnAdFullScreenContentOpened += () =>
        {
            Debug.Log("Interstitial ad full screen content opened.");
        };
        // Raised when the ad closed full screen content.
        interstitialAd.OnAdFullScreenContentClosed += () =>
        {
            Debug.Log("Interstitial ad full screen content closed.");
            LoadInterstitialAd();
        };
        // Raised when the ad failed to open full screen content.
        interstitialAd.OnAdFullScreenContentFailed += (AdError error) =>
        {
            Debug.LogError("Interstitial ad failed to open full screen content " +
                           "with error : " + error);
            LoadInterstitialAd();
        };
    }


}

By following this Unity AdMob Interstitial Ads tutorial, you’ve gained the knowledge and skills needed to effectively integrate full-screen ads into your application. Interstitial ads, when used strategically, can enhance your app’s monetization without significantly disrupting user experience. You’ve learned how to set up AdMob, configure your ad units, and implement the necessary code to manage ad display and functionality. With these tools at your disposal, you’re well-equipped to balance revenue generation with a smooth user experience, making your Unity project more financially viable and engaging. Happy coding and monetizing!

***CHECK FULL VIDEO TUTORIAL***

Visit www.UnitySourceCode.store

Leave a Reply

Shopping cart

0
image/svg+xml

No products in the cart.

Continue Shopping