[REQUIRED] Step 1: Describe your environment
- Unity version: 2022.2.8f1
- Google Mobile Ads Unity plugin version: 9.2.0
- Plugin installation method: .unitypackage import (Unity package manager, .unitypackage import)
- Platform: Unity Editor (iOS, Android, Unity Editor)
- Platform OS version: Android 9 (eg iOS 10, Android 9)
- Any specific devices issue occurs on: mobile device
- Mediation ad networks used, and their versions: Native ads
[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
// This is set up for native ads in editor
// This is code of native ads












