简体   繁体   中英

Admob native ads click is not working in unity (Android Platform)

I add the native ad in my unity game and ads details are shown properly but my ad click is not working.. I added the box collider manually and detect the click right but still ad is not redirecting to link.

I used test ids right now. If anyone can help me with this issue its great help. Thanks In Advance.

I done many solutions but nothing work for me yet. Below are the details of solutions I had try

1.I disabled the raycast target of every object of native ads 2.Added the box Collider manually to every object 3. I added below line in android manifest file under Activity block of UnityPlayerActivity

<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
  1. Try UnifiedNativeadview but this give me errors of unexistance.

Here is my code,

using UnityEngine;
using UnityEngine.UI;
using GoogleMobileAds.Api;
using System;

//Banner ad
public class Admob : MonoBehaviour
{
    private BannerView adBanner;
    private NativeAd adNative;
    private bool nativeLoaded = false;

    private string idApp, idBanner, idNative;

    [SerializeField] GameObject adNativePanel;
    [SerializeField] RawImage adIcon;
    [SerializeField] RawImage adChoices;
    [SerializeField] Text adHeadline;
    [SerializeField] Text adCallToAction;
    [SerializeField] Text adAdvertiser;


    void Awake ()
    {
        adNativePanel.SetActive (false); //hide ad panel
    }

    void Start ()
    {
        idApp = "ca-app-pub-3940256099942544~3347511713";
        idBanner = "ca-app-pub-3940256099942544/6300978111";
        idNative = "ca-app-pub-3940256099942544/2247696110";

        MobileAds.Initialize (idApp);

        RequestBannerAd ();
        RequestNativeAd ();
    }

    void Update ()
    {
        if (nativeLoaded) {
            nativeLoaded = false;

            Texture2D iconTexture = this.adNative.GetIconTexture ();
            Texture2D iconAdChoices = this.adNative.GetAdChoicesLogoTexture ();
            string headline = this.adNative.GetHeadlineText ();
            string cta = this.adNative.GetCallToActionText ();
            string advertiser = this.adNative.GetAdvertiserText ();
            adIcon.texture = iconTexture;
            adChoices.texture = iconAdChoices;
            adHeadline.text = headline;
            adAdvertiser.text = advertiser;
            adCallToAction.text = cta;

            //register gameobjects
            adNative.RegisterIconImageGameObject (adIcon.gameObject);
            adNative.RegisterAdChoicesLogoGameObject (adChoices.gameObject);
            adNative.RegisterHeadlineTextGameObject (adHeadline.gameObject);
            adNative.RegisterCallToActionGameObject (adCallToAction.gameObject);
            adNative.RegisterAdvertiserTextGameObject (adAdvertiser.gameObject);

            adNativePanel.SetActive (true); //show ad panel
        }
    }

    #region Banner Methods --------------------------------------------------

    public void RequestBannerAd ()
    {
        adBanner = new BannerView (idBanner, AdSize.Banner, AdPosition.Bottom);
        AdRequest request = AdRequestBuild ();
        adBanner.LoadAd (request);
    }

    public void DestroyBannerAd ()
    {
        if (adBanner != null)
            adBanner.Destroy ();
    }

    #endregion

    #region Native Ad Mehods ------------------------------------------------

    private void RequestNativeAd ()
    {
        AdLoader adLoader = new AdLoader.Builder (idNative).ForNativeAd ().Build ();
        adLoader.OnNativeAdLoaded += this.HandleOnNativeAdLoaded;
        adLoader.LoadAd (AdRequestBuild ());
    }

    //events
    private void HandleOnNativeAdLoaded (object sender, NativeAdEventArgs args)
    {
        this.adNative = args.nativeAd;
        nativeLoaded = true;
    }

    #endregion

    //------------------------------------------------------------------------
    AdRequest AdRequestBuild ()
    {
        return new AdRequest.Builder ().Build ();
    }

    void OnDestroy ()
    {
        DestroyBannerAd ();
    }

}

Did you read the first line on the 'Get Started' page for Native Ads in Unity? ( https://developers.google.com/admob/unity/native )

It says:

"Note: Native ads on Unity is in closed beta . To use native ads, contact your account manager."

(I was in the same boat as you: I had done everything correctly, but somehow it didn't work. Then I read that note about the closed beta and realized that that is most likely the explanation.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM