2

We have the problem with our AdManger viewability measurement that it is only tracked after scrolled out of view and back again.

We brought everything back to a simple ad UI and it still does not work as expected. Does anybody see something wrong in the code?

That’s the code we are using:

    @Composable
    fun AdTestScreen(viewModel: AdTestViewModel = getViewModel()) {
        val adItems by viewModel.adItems.collectAsState(initial = emptyList()) // our ad information comes from the backend
        val context = LocalContext.current
        val webViews = rememberSaveable(adItems) { adItems.map { generateAdManagerAdView(context, it) } }
    
        LazyColumn() {
            items(webViews) { adView ->
                Text(text = "Some Lorem Ipsum text..."
                AndroidView(
                    factory = {
                        adView.removeFromParent()
                        adView
                    }
                )
            }
        }
    }
    
    fun generateAdManagerAdView(context: Context, ad: Ad) =
        AdManagerAdView(context).apply {
            adUnitId = ad.adUnitId
            setAdSizes(ad.adSizes)
            doOnLayout {
                loadAd(AdManagerAdRequest.Builder().apply {
                    // some custom targeting is done
                }.build())
            }
        }

We are using the following versions:

    const val ads = "com.google.android.gms:play-services-ads:21.4.0"
    const val auth = "com.google.android.gms:play-services-auth:20.4.0"
    const val adsIdentifier = "com.google.android.gms:play-services-ads-identifier:18.0.1"
    
    const val kotlinVersion = "1.7.10"
    const val composeVersion = "1.2.1"
    const val composeCompilerVersion = "1.3.0"

Expected behaviour:

When the ad is displayed the measuring should start. For me this is defined as seeing many GMA Debug CONTENT .... "uri":"https://dt.adsafeprotected.com/dt?... requests in the logcat (after you enabled Google Ads Debug Mode https://support.google.com/google-ads/thread/13685676/enable-debug-logging-for-ads?hl=en). As long as the ad is displayed, the measurement calls are sent until a maximum is reached.

Current behaviour:

When the ad is displayed nothing is measured. Even when you scroll up and down (the Ad is always in a visible area), nothing is tracked. BUT: when the ad gets out of visible area and you go back, it starts measuring.

2
  • 2
    I had a not same but similar problem and found a workaround, wrote down here: stackoverflow.com/questions/76100292/… Commented Apr 25, 2023 at 10:48
  • 1
    Thanks @OyaCanli ! Your workaround has fixed our issue as well! I will link you and your answer in an answer or feel free to write it by your own :) Commented May 11, 2023 at 6:43

1 Answer 1

1

Thanks to @OyaCanli, I found a solution/workaround for this problem: Ad impressions are not count when AdManagerAdView is used with Jetpack Compose :

I found this workaround proposed in Kotlin slack for NativeAdView in Jetpack Compose, https://kotlinlang.slack.com/archives/CJLTWPH7S/p1664105063510709, and I improved it a bit. Calling adView.rootView.requestLayout() from onAdLoaded solved the issue and I see now onAdImpression is called right after onAdLoaded.

AdManagerAdView(context).apply {
    adUnitId = ad.id
    setAdSizes(*ad.sizes)
    appEventListener = createAppEventListener()
    adListener = object : AdListener() {
        override fun onAdLoaded() {
            super.onAdLoaded()
            rootView.requestLayout()
        }
    }
    loadAd(bannerAdModule.adRequest(ad))
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.