googleads / googleads-mobile-unity

Official Unity Plugin for the Google Mobile Ads SDK
https://developers.google.com/admob/unity
Apache License 2.0
1.38k stars 1.08k forks source link

Admob don't record impression and clicked of native ads #3631

Open AnKoCare opened 1 month ago

AnKoCare commented 1 month ago

[REQUIRED] Step 1: Describe your environment

[REQUIRED] Step 2: Describe the problem

Steps to reproduce:

Hi everyone, I am currently working on native advertising and have referenced the following source: https://youtu.be/M-XdptsCWtQ?si=PUZS3HU2RWNDwa56

I built the device and tested everything fine, native ads load normally, clicks will redirect to the store, but the problem is that Admob does not record the display and clicks. Everything like banners, inter, bonus ads work normally.

I have consulted documents in many support groups but have not found any effective way (have updated the ads sdk to the latest version), hope to receive support from everyone.

Relevant Code:

// This is code load and register native ads

region NativeAds

private NativeAd adNative;
public bool nativeLoaded;
private bool isLoadingNativeAds;

public void RequestNativeAd()
{
    Debug.Log("Loading native ad");
    if(isLoadingNativeAds)
    {
        Debug.Log("return because loading native ad");
        return;
    }
    isLoadingNativeAds = true;
    AdLoader adLoader = new AdLoader.Builder(nativeAdsId).ForNativeAd().Build();
    adLoader.OnNativeAdLoaded += HandleNativeAdLoaded;
    adLoader.OnAdFailedToLoad += HandleAdFailedToLoad;
    adLoader.OnNativeAdImpression += OnNativeAdImpression;

    AdRequest adRequest = new AdRequest();
    adLoader.LoadAd(adRequest);

    void HandleAdFailedToLoad(object sender, AdFailedToLoadEventArgs e)
    {
        Debug.LogError("native ads load failed");
        TrackingManager.instance.ad_native_show_failed();
        isLoadingNativeAds = false;
    }

    void HandleNativeAdLoaded(object sender, NativeAdEventArgs e)
    {
        Debug.LogError("native ads load completed");
        this.adNative = e.nativeAd;
        nativeLoaded = true;
        isLoadingNativeAds = false;
    }

    void OnNativeAdImpression(object sender, EventArgs e)
    {
        Debug.LogError("Native Ads Show Done");
    }
}

public void ShowNativeAds(GameObject adNativePanel, Image adIcon, Image adChoices, Text adHeadline, Text adBodyText, Text adCallToAction, Text adAdvertiser)
{
    if (this.adNative != null)
    {
        Debug.Log("Set up native ads");
        string headlineText = this.adNative.GetHeadlineText();
        adHeadline.color = Color.black;
        adHeadline.text = headlineText;

        string bodyText = this.adNative.GetBodyText();
        adBodyText.text = bodyText;

        string adCta = this.adNative.GetCallToActionText();
        adCallToAction.text = adCta;

        string adAdv = this.adNative.GetAdvertiserText();
        adAdvertiser.text = adAdv;

        Texture2D iconTexture = this.adNative.GetIconTexture();
        if (iconTexture != null)
        {
            adIcon.gameObject.SetActive(true);
            adIcon.sprite = Sprite.Create(iconTexture, new Rect(0, 0, iconTexture.width, iconTexture.height), new Vector2(.5f, .5f));
        }
        // else
        // {
        //     adIcon.gameObject.SetActive(false);
        // }

        Texture2D iconChoice = this.adNative.GetAdChoicesLogoTexture();
        if (iconChoice != null)
        {
            adChoices.gameObject.SetActive(true);
            adChoices.sprite = Sprite.Create(iconChoice, new Rect(0, 0, iconChoice.width, iconChoice.height), new Vector2(.5f, .5f));
        }
        // else
        // {
        //     adChoices.gameObject.SetActive(false);
        // }

        if (!adNative.RegisterIconImageGameObject(adIcon.gameObject))
        {
            Debug.LogError("error register icon");
        }

        if(!adNative.RegisterAdChoicesLogoGameObject(adChoices.gameObject))
        {
            Debug.LogError("error register ad choice");
        }

        if (!adNative.RegisterHeadlineTextGameObject(adHeadline.gameObject))
        {
            Debug.LogError("error register ad header text");
        }

        if (!adNative.RegisterBodyTextGameObject(adBodyText.gameObject))
        {
            Debug.LogError("error register ad body text");
        }

        if(!adNative.RegisterCallToActionGameObject(adCallToAction.gameObject))
        {
            Debug.LogError("error register ad call to action text");
        }

        if(!adNative.RegisterAdvertiserTextGameObject(adAdvertiser.gameObject))
        {
            Debug.LogError("error register ad advertiser text");
        }

        adNativePanel.SetActive(true);

        Debug.Log("call Show native ads done");
        TrackingManager.instance.ad_native_show();
        RequestNativeAd();
    }
    else
    {
        Debug.Log("native ads null");
        RequestNativeAd();
    }
}
#endregion

// This is code call request native ads public class PanelAdNative : MonoBehaviour { [SerializeField] private GameObject adNativePanel; [SerializeField] private Image adIcon; [SerializeField] private Image adChoices; [SerializeField] private Text adHeadline; [SerializeField] private Text adBodyText; [SerializeField] private Text adCallToAction; [SerializeField] private Text adAdvertiser; private bool isDestroy; private bool isHiddenAdsNative = false; void Awake () { adNativePanel.SetActive (false); //hide ad panel }

private async void Start()
{
    while (!GameManager.GetInstance().adsController.nativeLoaded)
    {
        if(isDestroy)
            return;
        if(GameManager.GetInstance().adsController.nativeLoaded)
        {
            Debug.Log("native ads reload successfully");
            break;
        }
        else
        {
            Debug.Log("Reload request native ads");
            GameManager.GetInstance().adsController.RequestNativeAd();
        }
        await Task.Delay(2000);
    }
    Debug.Log("Start get native ads");
    GameManager.GetInstance().adsController.nativeLoaded = false;
    GameManager.GetInstance().adsController.ShowNativeAds(adNativePanel, adIcon, adChoices, adHeadline, adBodyText, adCallToAction, adAdvertiser);
}

// This is issue IMG_1314 // This is set up native ads

Screenshot 2024-10-09 at 08 31 23 Screenshot 2024-10-09 at 08 32 16 Screenshot 2024-10-09 at 08 32 05 Screenshot 2024-10-09 at 08 31 58 Screenshot 2024-10-09 at 08 31 54 Screenshot 2024-10-09 at 08 31 50 Screenshot 2024-10-09 at 08 31 47 Screenshot 2024-10-09 at 08 31 43 Screenshot 2024-10-09 at 08 31 38 Screenshot 2024-10-09 at 08 38 29 Screenshot 2024-10-12 at 10 29 48 Screenshot 2024-10-12 at 10 31 53
vinkini commented 1 month ago

Hello, I would like to understand a bit more about your use case. I notice you have a canvas for placing the ad. Instead of Native Ads, did you consider Native Overlays. Native Overlays have the advantage of supporting Video ads as well as mediation. Also the SDK takes care of rendering ad so you don't have to lay out individual elements such as call to action, headline, etc.

AnKoCare commented 1 month ago

Hello, I would like to understand a bit more about your use case. I notice you have a canvas for placing the ad. Instead of Native Ads, did you consider Native Overlays. Native Overlays have the advantage of supporting Video ads as well as mediation. Also the SDK takes care of rendering ad so you don't have to lay out individual elements such as call to action, headline, etc.

Thank for your reply, I will try it.

NoelRecords commented 2 days ago

I am facing the same issue. The request and match rate for native ads are being counted, but impressions remain at zero. I checked the sample project for native overlay ads, but since native overlay ads did not fit well with the app’s UI, I need to use native ads.

Unity version : 2021.3.45f1 Google Mobile Ads Unity plugin version: 9.4.0 GoogleMobileAds-native : 7.4.0

vinkini commented 2 days ago

The NativeOverlay ads are quite customizable using the NativeTemplateStyle as demonstrated here. I would like to understand your use case better. Unless your application has 3D elements, the NativeOverlay should ideally work for most cases. I would encourage against using the Native Unity Plugin since its not being maintained currently.

NoelRecords commented 2 days ago

The NativeOverlay ads are quite customizable using the NativeTemplateStyle as demonstrated here. I would like to understand your use case better. Unless your application has 3D elements, the NativeOverlay should ideally work for most cases. I would encourage against using the Native Unity Plugin since its not being maintained currently.

I tried customizing various aspects using NativeTemplateStyle, but it didn’t match my app’s UI. With NativeTemplateID.Medium, the ad takes up more than half the screen on an iPhone SE3, while NativeTemplateID.Small feels more like a banner ad. Additionally, AdPosition doesn’t allow for fine adjustments, making it difficult to use for purposes other than simply displaying ads.