Whenever I click on any Admob native ad that I have made, this is the error that I encounter:
The ad slot cannot handle external click events. You must be part of the allow list to be able to report your click events.
This is the code that I have used:
var nativeAd by remember { mutableStateOf<NativeAd?>(null) }
ShowNativeAd(context, adUnitId) { ad ->
nativeAd = ad}
nativeAd?.let { ad ->
Column(
modifier = Modifier
.fillMaxWidth()
.padding(4.dp)
) {
ad.mediaContent?.let { mediaContent ->
if(nativeAd!!.mediaContent?.hasVideoContent() != true){
ad.images.firstOrNull()?.drawable?.let { drawable ->
Image(
bitmap = drawable.toBitmap().asImageBitmap(),
contentDescription = null,
modifier= Modifier
.fillMaxWidth()
.aspectRatio(mediaContent.aspectRatio)
.clickable {
ad.performClick(Bundle())
ad.recordImpression(Bundle())
Log.d("ads","Ad was clicked")
}
)
Text(
text = ad.headline ?: "",
modifier = Modifier
.padding(bottom = 8.dp)
)
}
}
where showNativeAd()
is another function I have used to load the Ads and then return it.
This is how the function looks like:
fun ShowNativeAd(context: Context, adUnitId: String, adLoadCallback: (NativeAd) -> Unit){
Log.d("ads","Loading Native Ad")
val adLoader = AdLoader.Builder(context, adUnitId)
.forNativeAd { ad : NativeAd ->
adLoadCallback(ad)
}
})
.withNativeAdOptions(NativeAdOptions.Builder()
.build())
.build()
adLoader.loadAd(AdRequest.Builder().build())
}
The Ad was clicked
is logged for sure, But I receive the above error that crashes the application. Any solutions?