Immersive Ads SDK
v1.5.3 beta
v1.5.3 beta
  • 👋Welcome to Immersive Ads SDK
  • Prerequisites
    • 📪Prerequisites
    • 🧙Demand Source setup
  • Integration
    • ⬇️Adding the SDK
    • 🔗App Linking
    • 🎬Scene setup
    • 🩺Testing the integration
    • ☑️Integration Checklist
    • 🛠️Troubleshoot
  • PRESENTATION
    • 🍥Ad Object Structure
    • 🍧Changing Ad Visuals
    • 🍨Extra Display Templates
  • 🔮Samples
Powered by GitBook
On this page
  • Ad Loading Failed
  • No Impression but Click
  • Impression but No Click
  • Build Issues with Gradle
  • Memory Management
  • What if the display template does not use the icon or big image?
  1. Integration

Troubleshoot

PreviousIntegration ChecklistNextAd Object Structure

Ad Loading Failed

  1. Make sure you have added the App ID inside the Google Ad Mob settings window.

  2. In the case of live ad id (Test mode off), this may happen if there is no fill from the Google server.

  3. You might run into this issue when using Unity Editor Version 2021 or above with Admob versions 8.x.x. To fix this, make sure you are building your application with IL2CPP as your scripting backend.

No Impression but Click

  1. If it’s a 3d game the camera and the ad unit must be on the side + Z world axis to get an impression.

  2. Make sure there is no collider between the main camera and the ad Unit.

  3. If you are instantiating ad prefabs in real-time try disabling the strip engine code option from the build option.

  4. If you have multiple camera’s on the scene make sure the camera which is looking toward the ad unit has the highest priority depth value.

  5. Make sure the Unity Event system component is present in the scene.

Impression but No Click

  1. Make sure there is no collider between the main camera and the ad Unit.

  2. Make sure the Unity Event system component is present in the scene.

  3. The screen space native ad is not placed inside a Canvas with Overlay render mode

Build Issues with Gradle

If you run into Gradle issues in Unity 2019 or 2020

  1. Check the Gradle version in the Unity Settings section and point the Gradle to the 2021 Unity version's Gradle file or above.

  2. Check if the Custom base Gradle Template is enabled from the Publishing settings option under project settings

  3. Change the gradle version inside the baseProjectTemplate.gradle (Found under Plugin > Android ) file to 4.0.0

  4. Check and uncheck the Android options inside the External Tools section of the Preferences only keep the Gradle option unchecked after changing the Gradle version for 2019 and 2020.

  5. Do a force resolve in the External Dependency Manager

  6. Check Minimum API Level and Target API Level under project settings>> Player section

  7. Check the API compatibility level to .Net 4x

  8. Check the device cable if it is connected when building the .apk to a device.

If you run into Gradle issues in Unity 2021 or above with Admob v8.6.0 or v8.7.0

Do the following if you run into the above issue.

  • Under Player Settings-> Publishing settings, Check if Custom Main Gradle Template, Custom Gradle Properties Template and Custom Gradle Settings Template are enabled.

  • Make sure the scripting backend is IL2CPP and Target API level is at least 33.

  • Just before you make a build, open External Tools section under Edit->Preferences. Check and uncheck the plugins to refresh the installation paths of JDK, NDK, SDK, and Gradle to avoid the warning shown below, especially after updating the required tools. It is a Unity Editor bug where the installation paths to the tools are not updated properly.

Memory Management

  • The downloaded ad textures build up in memory and may need manual handling in certain cases.

  • The accumulated textures are cleared when a scene change or reload happens. However, in the following cases, you should manually manage texture memory

    • Single scene setup

    • Long-running gameplay scene

    • Gameplay Restart/ Progression happens without any scene reload or change

  • Destroying texture assets is an expensive operation. The SDK avoids doing so during gameplay as what would be a good time for the SDK could be bad timing for the game and lead to a framerate drop at a critical point

  • You can manually invoke Resource.UnloadUnusedAssets() at a strategic point when the gameplay is not demanding to free up the texture memory

  • If you don't want to use Unity's UnloadUnusedAssets API, you can handle the textures at the level of each NativeAdHolder.

  • Here is a script that can be used as is or modified to suit your needs


using UnityEngine;
using GoogleMobileAds.Api;
using PubScale.SdkOne.NativeAds;
using PubScale.SdkOne;

public class NativeTextureReferences : MonoBehaviour
{

    [SerializeField] NativeAdHolder nativeAdHolder;

    Texture2D prevLoadedAdIconTex = null;
    Texture2D prevLoadedBigImgTex = null;
    Texture2D prevLoadedAdChoicesTex = null;

    NativeAdDisplayHandler curDisplayHandler;


    void Start()
    {
        if (nativeAdHolder != null)
        {
            ClearDummyAdSprites(nativeAdHolder);

            nativeAdHolder.Event_AdRequest += OnNewNativeAdRequested;
            nativeAdHolder.Event_AdLoaded += OnNativeAdLoaded;
        }
        else
            Debug.LogWarning("PubScaleSDK: Please assign a nativeAdHolder in NativeTextureReferences");

    }

    private void OnNewNativeAdRequested()
    {
        if (nativeAdHolder != null && nativeAdHolder.adDisplay != null)
        {
            curDisplayHandler = nativeAdHolder.adDisplay;

            if (curDisplayHandler != null)
            {
                // Ad Icon
                if (curDisplayHandler.adIconImg != null && curDisplayHandler.adIconImg.sprite != null)
                {
                    if (curDisplayHandler.adIconImg.sprite.texture != null)
                        prevLoadedAdIconTex = curDisplayHandler.adIconImg.sprite.texture;
                }

                // Big Image
                if (curDisplayHandler.imageTextures != null && curDisplayHandler.imageTextures.sprite != null)
                {
                    if (curDisplayHandler.imageTextures.sprite.texture != null)
                        prevLoadedBigImgTex = curDisplayHandler.imageTextures.sprite.texture;
                }

                // Ad Choices
                if (curDisplayHandler.adChoicesImg != null && curDisplayHandler.adChoicesImg.sprite != null)
                {
                    if (curDisplayHandler.adChoicesImg.sprite.texture != null)
                        prevLoadedAdChoicesTex = curDisplayHandler.adChoicesImg.sprite.texture;
                }

            }
        }
    }

    private void OnNativeAdLoaded(object arg1, NativeAdEventArgs args)
    {
        if (prevLoadedAdIconTex != null)
        {
            Texture2D tempIconTex = prevLoadedAdIconTex;
            prevLoadedAdIconTex = null;
            Destroy(tempIconTex);   // You can destroy or add to list and Destroy in batch at a convenient point in gameplay
        }

        if (prevLoadedBigImgTex != null)
        {
            Texture2D tempBigImgTex = prevLoadedBigImgTex;
            prevLoadedBigImgTex = null;
            Destroy(tempBigImgTex);  // You can destroy or add to list and Destroy in batch at a convenient point in gameplay
        }

        if (prevLoadedAdChoicesTex != null)
        {
            Texture2D tempAdChoicesTex = prevLoadedAdChoicesTex;
            prevLoadedAdChoicesTex = null;
            Destroy(tempAdChoicesTex); // same as above
        }
    }



    void ClearDummyAdSprites(NativeAdHolder natAdHolder)
    {
        curDisplayHandler = nativeAdHolder.adDisplay;

        RemoveDefaultTextureReferences(curDisplayHandler);

        if (natAdHolder.UseExtraFormats)
        {
            if (natAdHolder.landscapeAdFormats != null && natAdHolder.landscapeAdFormats.Length > 0)
            {
                foreach (NativeAdDisplayHandler displayHandler in natAdHolder.landscapeAdFormats)
                    RemoveDefaultTextureReferences(displayHandler);
            }

            if (natAdHolder.potraitAdFormats != null && natAdHolder.potraitAdFormats.Length > 0)
            {
                foreach (NativeAdDisplayHandler displayHandler in natAdHolder.potraitAdFormats)
                    RemoveDefaultTextureReferences(displayHandler);
            }

            if (natAdHolder.nonMediaType != null && natAdHolder.nonMediaType.Length > 0)
            {
                foreach (NativeAdDisplayHandler displayHandler in natAdHolder.nonMediaType)
                    RemoveDefaultTextureReferences(displayHandler);
            }
        }
    }

    void RemoveDefaultTextureReferences(NativeAdDisplayHandler curDisplayHanlder)
    {
        // Dummy Ad Logo Image
        if (curDisplayHanlder.adIconImg != null)
            ClearImageSprite(curDisplayHanlder.adIconImg);

        // Dummy Big Image
        if (curDisplayHanlder.imageTextures != null)
            ClearImageSprite(curDisplayHanlder.imageTextures);

        // Dummy Ad Choices Icon image
        if (curDisplayHanlder.adChoicesImg != null)
            ClearImageSprite(curDisplayHanlder.adChoicesImg);
    }

    void ClearImageSprite(UnityEngine.UI.Image img)
    {
        if (img != null && img.sprite != null)
            img.sprite = null;
    }

}

What if the display template does not use the icon or big image?

  • For display templates that show a subset of the ad media:

    • Do not delete the unused media game object and keep its reference and settings in the DisplayHandler script as it is. No change is required.

    • Uncheck it's Image component (but let it remain on the game object)

    • Make adjustments to ensure it does not overlap any displayed ad elements

  • When the ad loads, the ad icon and big media are loaded into memory (even if not shown). As in the script above you can get the reference to the texture and destroy at a convenient point in the game flow when the intensity is low.

Make sure Enable kotlinx.coroutines packaging option in GMA settings is checked. Learn more about the issue .

Required Gradle version is 6.7.1 or above for Unity versions 2022.1 and later. Refer to know more about upgrading Gradle and to check to verify Gradle Compatibility with Unity versions.

🛠️
here
this
this
Does not use Big Image. Displays only the ad icon.
Does not use Ad Icon. Displays only the Big Image.