常见误区
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
AdSense Management API 提供用于生成新的和已保存的报告的调用。这些报告可以包含简单的分析结果(例如每日收入),也可以包含非常复杂的表格,其中包含每个国家/地区每个自定义渠道的点击率。本指南介绍了一系列应正确处理的极端情况,以实现与 API 的强大集成。
报告结构
报告结果以 ReportResult
对象的形式返回。如需了解完整详细信息,请参阅报告响应参考文档。
使用按时间顺序的维度:DATE、WEEK 和 MONTH
报告可以为空或有缺漏
如果在请求中指定的时间段内没有任何活动,则系统不会生成广告请求,并且报告服务不会显示这些时间段内的行。绘制图表时,这一点很重要。
如需了解详情,请参阅日期填充指南。
在同一报告中请求 MONTH 和 WEEK 维度
该报告可能会造成负面或意想不到的后果。如果某一周属于两个不同的月份,则该周会显示两行,每行对应一个月份。
示例
维度 | 指标 | 开始日期 | 结束日期 |
WEEK
MONTH |
CLICKS | 2014-04-28 |
2014-05-03 |
返回:
MONTH | WEEK * | CLICKS |
2014-04 |
2014-04-27 |
50 |
2014-05 |
2014-04-27 |
43 |
* 一周的第一天
解决方案
从报告中移除“MONTH
”。
整理维度值
请求与平台(桌面设备、高端移动设备等)相关的维度时,将仅显示发生活动的平台。如果给定的日期、周或月没有来自高端移动设备的访问,则不会显示该类别的信息。
示例
维度 | 指标 | 开始日期 | 结束日期 |
PLATFORM_TYPE_NAME
MONTH |
AD_REQUESTS |
2014-02-01 | 2014-03-31 |
返回:
月 | PLATFORM_TYPE_NAME | AD_REQUESTS |
2014-03 |
桌面版 |
100 |
2014-03 |
高端移动设备 |
5 |
2014-04 |
桌面版 |
75 |
解决方案
处理报告结果时,假定结果中未显示的所有维度值均为零:
月 | PLATFORM_TYPE_NAME | AD_REQUESTS |
2014-03 |
桌面版 |
100 |
2014-03 |
高端移动设备 |
5 |
2014-04 |
桌面版 |
75 |
2014-04 |
高端移动设备 |
0 |
合并多个连续报告
有时,报告过大,无法一次性生成,必须进行批量处理。如果您的应用会执行此操作,请考虑以下情况:
- 如果您使用的是
WEEK
或 MONTH
维度,并在一周或月中间对报告进行拆分,则每个报告都会包含包含不同数据的重复条目。
- 确保所有报告都具有相同的指标和维度,因为使用不同的维度可能无法合并数据。
特殊账号
您的部分用户的 AdSense 帐号可能带有您意想不到或不了解的属性。请务必考虑以下因素:
- 拥有数千个域名或网站的发布商
- 拥有数千个广告单元或自定义渠道的发布商
- 想要为多个广告客户(AdSense 搜索广告、AdSense 视频广告等)生成报告的发布商
多个账号
用户可以访问多个 AdSense 帐号。因此,每次调用该 API 时都必须指定帐号 ID。调用 accounts.list
会获取帐号列表,并且系统应向用户显示帐号选择器对话框。如果提取的帐号数为一个,则可以绕过该错误。
时区更改
AdSense 发布商可以随时更改时区,这可能会导致报告中出现高峰或低谷。如需了解详情,请参阅有关本地时区报告的指南。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003eThe AdSense Management API allows for the generation of reports with varying levels of complexity, ranging from basic earnings data to detailed click-through rates across dimensions like custom channels and countries.\u003c/p\u003e\n"],["\u003cp\u003eWhen generating reports, be aware of potential edge cases like empty reports, gaps in data for inactive periods, and unexpected results when combining certain dimensions like \u003ccode\u003eWEEK\u003c/code\u003e and \u003ccode\u003eMONTH\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eEnsure accurate report interpretation by accounting for missing dimension values, which should be treated as zero, and be cautious when combining multiple reports to avoid data duplication or incompatibility.\u003c/p\u003e\n"],["\u003cp\u003eConsider special scenarios, such as publishers with numerous domains, ad units, or custom channels, and accommodate users with multiple AdSense accounts by implementing account selection.\u003c/p\u003e\n"],["\u003cp\u003eAccount for potential data fluctuations due to AdSense publisher timezone changes, which can impact report accuracy.\u003c/p\u003e\n"]]],["The AdSense Management API allows generating reports with diverse analytics. Key considerations for integration include handling empty reports or gaps if there's no activity. Requesting `MONTH` and `WEEK` dimensions together can cause duplicate rows. When collating dimensions like platforms, assume zero for missing values. Combining large reports can create duplicate entries if split mid-week or month. Also, account for special user types with numerous domains, ad units, or multiple ad clients and time zone changes. Every call needs an account ID.\n"],null,["# Common pitfalls\n\nThe AdSense Management API has calls to generate new and saved reports. They can\ncontain simple analytics like earnings per day or very complex tables of\nclick-through rates per custom channel per country. This guide presents a list\nof edge cases that should be correctly handled for a robust integration with\nthe APIs.\n\nReport structure\n----------------\n\nReport results are returned as a `ReportResult` object. See\n[the report\nresponse reference](/adsense/management/reference/rest/v2/ReportResult) for full detials.\n\nUsing chronological dimensions: DATE, WEEK, and MONTH\n-----------------------------------------------------\n\n### Reports can be empty or have gaps\n\nIf there was no activity during the time period specified in the request, no\nad requests are generated and the report service won't show rows for those time\nperiods. This is important if you are, for example, plotting a graph.\n\nCheck out the [Filling in\nDates guide](/adsense/management/reporting/missing_dates) for more information.\n\n### Requesting MONTH and WEEK dimensions in the same report\n\nThis report can have **negative or unexpected** consequences. If a week\nbelongs to two different months, it will show two rows for the same week, one\nfor each month.\n\n#### Example\n\n| Dimensions | Metrics | Start date | End date |\n|----------------|----------|------------|------------|\n| `WEEK` `MONTH` | `CLICKS` | 2014-04-28 | 2014-05-03 |\n\n##### Returns:\n\n| `MONTH` | `WEEK`\\* | `CLICKS` |\n|---------|----------------|----------|\n| 2014-04 | 2014-04-27 | 50 |\n| 2014-05 | **2014-04-27** | 43 |\n\n\\* first day of the week\n\n##### Solution\n\nRemove `MONTH` from the report.\n\n| `WEEK` | `CLICKS` |\n|------------|----------|\n| 2014-04-27 | 93 |\n\nCollating dimension values\n--------------------------\n\nWhen requesting dimensions like the ones related to, for example,\n**platforms** (desktop, high-end mobile devices, etc.), only the platforms\nwith activity will be shown. If a given day, week, or month has no visits from\nhigh-end mobile devices, it will have no information for that category.\n\n#### Example\n\n| Dimensions | Metrics | Start date | End date |\n|------------------------------|---------------|------------|------------|\n| `PLATFORM_TYPE_NAME` `MONTH` | `AD_REQUESTS` | 2014-02-01 | 2014-03-31 |\n\n##### Returns:\n\n| MONTH | PLATFORM_TYPE_NAME | AD_REQUESTS |\n|---------|-------------------------|-------------|\n| 2014-03 | Desktop | 100 |\n| 2014-03 | High-end mobile devices | 5 |\n| 2014-04 | Desktop | 75 |\n\n##### Solution\n\nWhen processing the report results, assume a value of zero for any dimension\nvalues that do not appear in the results:\n\n| MONTH | PLATFORM_TYPE_NAME | AD_REQUESTS |\n|-------------|-----------------------------|-------------|\n| 2014-03 | Desktop | 100 |\n| 2014-03 | High-end mobile devices | 5 |\n| 2014-04 | Desktop | 75 |\n| **2014-04** | **High-end mobile devices** | **0** |\n\nCombining multiple contiguous reports\n-------------------------------------\n\nSometimes a report is too large to be generated all at once and it has to be\nbatched. If your app does this, consider these cases:\n\n- If you're using `WEEK` or `MONTH` dimensions and you're splitting the report in the middle of a week or month, each report will have duplicated entries with different data.\n- Make sure all the reports have the same metrics and dimensions, as data might not be combinable using different dimensions.\n\nSpecial accounts\n----------------\n\nSome of your users might have AdSense accounts with attributes that you\ndon't expect or know about. Make sure to take into account:\n\n- Publishers with thousands of domains or sites\n- Publishers with thousands of ad units or custom channels\n- Publishers that would like to report on multiple ad clients (AdSense for Search, AdSense for Video, etc.)\n\nMultiple accounts\n-----------------\n\nUsers can have access to more than one AdSense account. An account ID has to\nbe specified for every call to the API for this reason. A call to\n`accounts.list` fetches a list of accounts and an account chooser\ndialog should be displayed to the user. It can be bypassed if the number of\nfetched accounts is one.\n\nTime zone changes\n-----------------\n\nAdSense Publishers can change their timezone at any time and this can\nproduce spikes or dips in the reports. Read the guide about\n[Local Time Zone Reporting](/adsense/management/timezone) for more\ninformation."]]