谷歌广告API无法获取video_view_rate等视频指标求助
谷歌广告API视频指标返回0的解决方法
核心问题诊断
你遇到的video_view_rate、video_quartile_p25_rate等指标返回0的问题,主要是数据类型格式化错误导致的,同时需排查查询范围和广告组类型的合理性。
具体解决方案
1. 修正数据输出格式
这些视频指标属于浮点数/百分比类型,但你在printf中使用了整数格式符%d,会直接截断小数部分,导致显示为0。
修改后的printf代码:
printf( "Ad group ID %d in campaign ID %d group Status %d Impressions %d clicks %d video_view %d video_view_rate %.4f average_cpv %d cost_micros %d video_quartile_p25_rate %.4f video_quartile_p50_rate %.4f video_quartile_p75_rate %.4f video_quartile_p100_rate %.4f %s", $googleAdsRow->getAdGroup()->getId(), $googleAdsRow->getCampaign()->getId(), $googleAdsRow->getAdGroup()->getStatus(), $googleAdsRow->getMetrics()->getImpressions(), $googleAdsRow->getMetrics()->getClicks(), $googleAdsRow->getMetrics()->getVideoViews(), $googleAdsRow->getMetrics()->getVideoViewRate(), $googleAdsRow->getMetrics()->getAverageCpv(), $googleAdsRow->getMetrics()->getCostMicros(), $googleAdsRow->getMetrics()->getVideoQuartileP25Rate(), $googleAdsRow->getMetrics()->getVideoQuartileP50Rate(), $googleAdsRow->getMetrics()->getVideoQuartileP75Rate(), $googleAdsRow->getMetrics()->getVideoQuartileP100Rate(), PHP_EOL );
- 用
%.4f保留4位小数,可根据需求调整精度(比如%.2f显示两位小数)。
2. 指定查询时间范围
谷歌广告API默认时间范围可能不符合数据需求,建议在查询语句中明确时间范围,比如查询最近30天的数据:
SELECT campaign.id, ad_group.id, ad_group.name, metrics.impressions, metrics.video_views, metrics.clicks, metrics.video_view_rate, metrics.average_cpv, metrics.cost_micros, metrics.video_quartile_p25_rate, metrics.video_quartile_p50_rate, metrics.video_quartile_p75_rate, metrics.video_quartile_p100_rate, ad_group.status FROM ad_group WHERE ad_group.id IN (11111222233) AND segments.date DURING LAST_30_DAYS
3. 验证广告组类型
只有视频广告组才会产生这些视频四分位指标,如果你的广告组是搜索/展示类,指标自然为0。可通过添加ad_group.type字段查询确认:返回值为VIDEO才是视频广告组。
内容的提问来源于stack exchange,提问作者Chirag Vaghela
相关产品推荐
相关产品推荐

