RE: [google-admob-ads-sdk] Lack of impressions event in jetpack compose

611 views
Skip to first unread message
Message has been deleted

Mobile Ads SDK Forum Advisor

unread,
Sep 22, 2022, 1:58:46 PM9/22/22
to tomasz.k...@gmail.com, google-adm...@googlegroups.com

Hi Tomasz,

Thanks for reaching out to the GMA SDK Forum.

I had to delete your post since sensitive apps were posted publicly. Moving forward, you may reply privately to author option. For your reference, I’ve pasted below post content:

“When AdManagerAdView is used in jetpack compose view, impression events and impression callback is not called when 1px is rendered on the screen.”


Could you confirm if said behavior is observed in our sample apps without using JetPack compose? I was able to test your sample app to load test ads, this could be an issue with the implementation. Upon checking, the impression callback was fired after coming back from the background, and the ad became visible when the new screen was painted. Have you tried to ​​set the ad during the doOnLayout method in jetpack compose? We would like to request screen video recording showing the issue, so that we can investigate further. 
 

If the file(s) you are looking to share are less than 25mb in total you can attach them to this case on your next reply. If you are having trouble attaching your file to this case or if your file(s) are larger than 25mb, you can share your files with me by performing the following steps:

 

1. Navigate to

https://docs.google.com/forms/d/e/1FAIpQLSfkAiXMeYP-fw1W3Z-tT9uwmATEKO5X6S-th0gR2ezdKaaqfg/viewform?usp=pp_url&entry.400550049=Mobile+Ads+SDK&entry.460850823=5004Q00002eeZUgQAM&entry.80707362=00132201

2. Fill out all fields, and attach your file(s).

3. Please reply back on this thread when you have uploaded your file(s). Please do not share this link.



Regards,

Google Logo
Yasar
Mobile Ads SDK Team
 

 

 



ref:_00D1U1174p._5004Q2eeZUg:ref

Oya Canlı

unread,
Apr 24, 2023, 8:38:37 AM4/24/23
to Google Mobile Ads SDK Developers
Hello! I have the same issue after converting a screen to Compose. AdManagerAdView wrapped in a Compose AndroidView, is successfully loaded and shown, but impressions are not counted. onAdImpression method is not called on those views. My code is something like this:
AndroidView( factory = { context -> val unitId = AdUtils.buildAdUnitId(context, adMetadata) val builder = AdManagerAdRequest.Builder() //... set extra params.. AdManagerAdView(context.applicationContext).apply { setAdSizes(*adMetadata.adSizes) adUnitId = unitId importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_NO adListener = object : AdListener() { override fun onAdLoaded() { super.onAdLoaded() Timber.e("ad loaded location ${adMetadata.location} position ${adMetadata.position}") } override fun onAdFailedToLoad(adError: LoadAdError) { super.onAdFailedToLoad(adError) Timber.e("ad load failed: message = ${adError.message}, cause = ${adError.cause}, response info = ${adError.responseInfo}") } override fun onAdImpression() { super.onAdImpression() Timber.e("onAdImpression location ${adMetadata.location} position ${adMetadata.position}") } } loadAd(builder.build()) } } ) Interestingly, if I pause the application and resume, onAdImpression is called. Or if I navigate towards another screen, onAdImpression is called for the screen I am leaving. 
I am using version 21.5.0
I don't have a problem on another screen which uses views and recyclerviews. Only on the page that I converted to Compose. 
Is this a bug or is there another recommended way of using ads in compose?

Mobile Ads SDK Forum Advisor

unread,
Apr 24, 2023, 2:39:53 PM4/24/23
to oya...@gmail.com, google-adm...@googlegroups.com

Hi Oya,

Thank you for reaching out to us.

Before we can confirm if this is a bug or before we can recommend other way, can you confirm if you're able to replicate this behavior in one of our sample app (https://github.com/googleads/googleads-mobile-android-examples)? If yes, kindly provide it to us and the following information below for us to further check.

  • Sample app project of your implementation or one of our sample app where this behavior is reproducible
  • Steps to replicate
  • Screen recording of the behavior
  • Device name and versions affected
  • App ID

You can provide the following details via reply privately to author option or directly provide it to the link below.

If the file(s) you are looking to share are less than 25mb in total you can attach them to this case on your next reply. If you are having trouble attaching your file to this case or if your file(s) are larger than 25mb, you can share your files with me by performing the following steps:

1. Navigate to https://docs.google.com/forms/d/e/1FAIpQLSfkAiXMeYP-fw1W3Z-tT9uwmATEKO5X6S-th0gR2ezdKaaqfg/viewform?usp=pp_url&entry.400550049=Mobile+Ads+SDK&entry.460850823=5004Q00002eeZUgQAM&entry.80707362=00132201

2. Fill out all fields, and attach your file(s).

3. Please reply back on this thread when you have uploaded your file(s). Please do not share this link.

Regards,

Google Logo Mobile Ads SDK Team


ref:_00D1U1174p._5004Q2eeZUg:ref

Oya Canlı

unread,
Apr 24, 2023, 4:50:06 PM4/24/23
to Google Mobile Ads SDK Developers
Your sample is not using Jetpack Compose as far as I see. This is a problem when AdManagerAdView is used with Jatpack Compose. I see another thread mentioning the same problem for NativeAdView with Jetpack Compose and the workaround the developer proposed there worked for me as well: https://groups.google.com/g/google-admob-ads-sdk/c/9rduZS_2bpE/m/60ozaDHkBwAJ
Yet, that's an ugly workaround. I hope this can be fixed (if it is a bug) or maybe you could provide us a sample on how to use AdManagerAdView or NativeAdView with Jetpack Compose.

I can't share my client's project unfortunately, but I will try to prepare a simple sample. 

Peter Németh

unread,
Jun 12, 2023, 9:38:24 AM6/12/23
to Google Mobile Ads SDK Developers
Hello,

I am facing the very same issue. Here is a code snippet to reproduce the issue when using NativeAdView in Compose:

@Composable
fun NativeAdViewCell(
modifier: Modifier = Modifier,
viewModel: NativeAdViewModel = koinViewModel()
) {
val nativeAd: NativeAd? by viewModel.nativeAd.collectAsStateWithLifecycle()

Box(
modifier = modifier.fillMaxWidth(),
) {
AndroidViewBinding(
factory = NativeBannerAdBinding::inflate,
modifier = Modifier
.fillMaxWidth(),
update = {
nativeAd?.let { na ->
adHeadline.text = na.headline
adCallToAction.text = na.callToAction

adIcon.isGone = na.icon == null
adIcon.setImageDrawable(na.icon?.drawable)

val ratingVisible = na.starRating != null
val advertiserVisible = ratingVisible.not() && na.advertiser != null
val storeVisible = advertiserVisible.not() && na.store != null

adPrice.isVisible = ratingVisible && na.price != null
adPrice.text = na.price

adStars.isVisible = ratingVisible
na.starRating?.let {
adStars.rating = it.toFloat()
}

adAdvertiser.isVisible = advertiserVisible
adAdvertiser.text = na.advertiser

adStore.isVisible = storeVisible
adStore.text = na.store
adView.setNativeAd(na)
}
}
)
}
}

I guess I do not need to provide the loading of the NativeAd. During the loading the listener is set via "withAdListener". As mentioned in this thread earlier, the "onAdImpression" is not called after the ad is shown (neither when the ad is reloaded multiple times). The "onAdImpression" is triggered only if the user returns to the screen.

Steps to reproduce (reproducible with both test and real AdUnitIds):
- Create implementation of NativeAdView via AndroidViewBinding in Composable.
- Load a NativeAd with AdListener set to track Impressions
- After the NativeAd is loaded, set it to the NativeAdView (see code-snippet)
- Ad is shown, but impression is not tracked (onAdLoaded is triggered)

Regards,
Peter

Mobile Ads SDK Forum Advisor

unread,
Jun 16, 2023, 3:43:11 AM6/16/23
to peter.n...@gmail.com, google-adm...@googlegroups.com
Hello Peter,


Thank you for reaching out to us.

Can you confirm if you're able to replicate this behavior in one of our sample app (https://github.com/googleads/googleads-mobile-android-examples)? If so, kindly provide it to us and the following information below for us to further investigate.

  • Sample app project of your implementation or one of our sample app where this behavior is reproducible
  • Steps to replicate
  • Screen recording of the behavior
  • Device name and versions affected
  • App ID

You can provide the following details via reply privately to author option or directly provide it to the link below.

If the file(s) you are looking to share are less than 25mb in total you can attach them to this case on your next reply. If you are having trouble attaching your file to this case or if your file(s) are larger than 25mb, you can share your files with me by performing the following steps:

1. Navigate to https://docs.google.com/forms/d/e/1FAIpQLSfkAiXMeYP-fw1W3Z-tT9uwmATEKO5X6S-th0gR2ezdKaaqfg/viewform?usp=pp_url&entry.400550049=Mobile+Ads+SDK&entry.460850823=5004Q00002eeZUgQAM&entry.80707362=00132201

2. Fill out all fields, and attach your file(s).

3. Please reply back on this thread when you have uploaded your file(s). Please do not share this link.

This message is in relation to case "ref:_00D1U1174p._5004Q2eeZUg:ref"

Thanks,

 
Google Logo Mobile Ads SDK Team


Reply all
Reply to author
Forward
0 new messages