You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Compose中Google AdManager可见性测量异常求助

Google AdManager可见性测量异常:仅广告滚出再返回才触发统计

我们在使用Google AdManager时遇到可见性测量异常:广告首次显示时不会触发可见性统计,即使广告始终保持可见状态,上下滚动也不会产生测量记录;只有当广告滚出视图区域后再返回可见状态,测量请求才会正常启动。我们已经将广告UI简化至最简形式,但问题仍未解决,恳请帮忙排查代码问题。

代码实现

广告展示页面Composable

@Composable
fun AdTestScreen(viewModel: AdTestViewModel = getViewModel()) {
    val adItems by viewModel.adItems.collectAsState(initial = emptyList()) // 广告信息来自后端
    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
                }
            )
        }
    }
}

AdManagerAdView生成函数

fun generateAdManagerAdView(context: Context, ad: Ad) =
    AdManagerAdView(context).apply {
        adUnitId = ad.adUnitId
        setAdSizes(ad.adSizes)
        doOnLayout {
            loadAd(AdManagerAdRequest.Builder().apply {
                // 执行部分自定义定向配置
            }.build())
        }
    }

依赖版本

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"

预期与当前行为

预期行为

广告显示时即开始可见性测量,Logcat中会出现大量GMA Debug CONTENT .... "uri":"https://dt.adsafeprotected.com/dt?..."请求(需开启Google Ads调试模式)。广告持续显示期间,测量请求会持续发送直至达到上限。

当前行为

广告首次显示时无任何测量记录,即使广告始终可见,上下滚动也不会触发统计;但当广告滚出视图区域后再返回可见状态时,测量会正常启动。

内容的提问来源于stack exchange,提问作者museYke

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 13:01:24