使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
AdSense 广告代码用于启用广告投放和收益分成。您需要在用户可以选择通过 AdSense 实现内容变现的每个网页上放置 AdSense 广告代码。
您实现此步骤的方式可能取决于广告设置控制以及您要向用户提供的广告体验:
- 如果广告设置由您控制,那么您可以决定要支持的广告类型和展示位置,并且可以向用户的网站添加广告代码,就像是您自己的网站一样。您在 AdSense 账号中创建广告单元,但修改了 data-ad-client 和 data-ad-host 参数
- 如果您要将广告设置的控制权委派给您的用户,那么可能需要询问用户他们在广告类型和展示位置(左侧、右侧、顶部、底部等)方面的偏好设置,然后使用这些偏好设置完成代码植入。请注意,为了支持原生广告,广告代码需要一个广告单元 ID,您需要从用户那里收集该广告单元 ID。
广告代码参数
您需要修改广告代码中的两个必需参数。这些参数用于确定要投放的广告以及您与用户之间的收益分成。设置这些参数可指定平台的发布商 ID 和用户的发布商 ID:您还可以修改一些其他参数,具体取决于所用的广告格式。
参数 |
是否为必填项? |
说明和示例 |
data-ad-client |
是 |
您用户的 AdSense 内容广告发布商 ID(字符串)。此值由用户通过注册流程提供。此值是启动收益分成所必需的值。
对于 AdSense 内容广告,请在此字符串前面附加“ca-”。
请注意,此字符串也会显示在脚本代码的来源网址中,位于参数名称 client 下。
示例:
data-ad-client="ca-pub-1234"
src=".../adsbygoogle.js?client=ca-pub-1234&host=ca-host-pub-5678"
|
data-ad-host |
是 |
这是您的平台的托管媒体资源 ID(字符串)。此值用于标识您的平台的 AdSense 账号,也是启动广告投放所必需的值。
对于 AdSense 内容广告,请在此字符串前面附加“ca-host-”。
请注意,此参数还会显示在脚本代码的来源网址中,位于参数名称 host 下。
示例:
data-ad-host="ca-host-pub-5678"
src=".../adsbygoogle.js?client=ca-pub-1234&host=ca-host-pub-5678"
|
data-ad-slot |
对于展示广告单元,不是必需参数
对于其他格式的广告单元,是必需参数
|
这是与广告单元相关联的 ID。对于展示广告单元,此 ID 是可选字段;但对于其他格式的广告单元,这是必填字段。存在广告单元 ID 时,系统会在广告投放期间使用与相应广告单元相关联的设置。在广告投放期间,我们会同时在平台 (data-ad-host ) 和子级 (data-ad-client ) 账号中查找此广告单元 ID。此参数还可用于填充 AdSense 中的“广告单元”报告(此报告将仅在相应广告单元所属的账号中填充)。
|
data-ad-host-channel |
否 |
此参数用于生成报告。如需了解详情,请参阅“报告”部分。
|
重要提示:如果您的广告代码中没有 data-ad-host
参数,AdSense 将会使用 data-ad-client
参数提供的值继续投放广告。但是,您的平台账号不会在其账号中获得任何展示次数,因此不会获得任何收益分成。或者,您也可以使用 google-adsense-platform 元标记,确保广告请求中包含您的托管发布商 ID。
此外,请确保将正确的 data-ad-client
发布商 ID 放入代码中,以免将收入归因到错误的用户。
广告代码示例
下面列出了 AFP 支持的每种广告类型的代码示例。详细了解 AdSense 中的广告单元和自动广告。
展示广告单元代码(自适应)
<script async
src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1234&host=ca-host-pub-5678"
crossorigin="anonymous">
</script>
<ins class="adsbygoogle"
style="display:block;"
data-ad-client="ca-pub-1234"
data-ad-host="ca-host-pub-5678"
data-ad-format="auto">
</ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
展示广告单元代码(固定尺寸)
<script async
src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1234&host=ca-host-pub-5678"
crossorigin="anonymous">
</script>
<ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-1234"
data-ad-host="ca-host-pub-5678">
</ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
AMP 展示广告单元(自适应)
您需要将以下代码放置在页面的 <head>
中:
<script async custom-element="amp-ad" src="https://cdn.ampproject.org/v0/amp-ad-0.1.js"></script>
以下是放置到 <body>
中的广告单元代码段:
<amp-ad
width="100vw"
height="320"
type="adsense"
data-ad-client="ca-pub-1234"
data-ad-host="ca-host-pub-5678"
data-ad-slot=""
data-auto-format="rspv"
data-full-width="">
<div overflow="">
</amp-ad>
AMP 展示广告单元(固定尺寸)
您需要将以下代码放置在页面的 <head>
中:
<script async custom-element="amp-ad" src="https://cdn.ampproject.org/v0/amp-ad-0.1.js"></script>
以下是放置到 <body>
中的广告单元代码段:
<amp-ad
layout="fixed"
width="300"
height="600"
type="adsense"
data-ad-client="ca-pub-1234"
data-ad-host="ca-host-pub-5678">
</amp-ad>
自动广告
最好将以下广告代码放置在 <head>
元素中,或者放置在页面上尽可能靠近顶部的位置。
<script async
src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1234&host=ca-host-pub-5678"
crossorigin="anonymous">
</script>
通过 Ad Placement API 投放广告
Ad Placement API 目前支持插页式广告和激励广告。如需了解如何实现该 API 并对其进行自定义,请参阅 Ad Placement API 开发者文档。
AdSense for Platforms 适用于这些格式(目前仅适用于网络流量)。唯一的要求是将 data-ad-host
参数添加到主广告代码中。请参见下面的示例。
<script async
src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1234&host=ca-host-pub-5678"
crossorigin="anonymous">
</script>
<script>
window.adsbygoogle = window.adsbygoogle || [];
var adBreak = adConfig = function(o) {adsbygoogle.push(o);}
</script>
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
[null,null,[],[[["\u003cp\u003eAdSense ad tags are essential for ad serving and revenue sharing within AdSense for Platforms (AFP), requiring placement on every monetized page.\u003c/p\u003e\n"],["\u003cp\u003eTwo key parameters, \u003ccode\u003edata-ad-client\u003c/code\u003e (user's publisher ID) and \u003ccode\u003edata-ad-host\u003c/code\u003e (platform's publisher ID), must be modified in the ad tag for proper functionality.\u003c/p\u003e\n"],["\u003cp\u003eAFP supports various ad types and formats, including display, AMP, and Auto ads, each with specific code implementations.\u003c/p\u003e\n"],["\u003cp\u003eEnsure the correct \u003ccode\u003edata-ad-client\u003c/code\u003e and \u003ccode\u003edata-ad-host\u003c/code\u003e values are used for accurate revenue attribution and platform participation.\u003c/p\u003e\n"]]],["Ad serving and revenue sharing require placing the AdSense ad tag on user pages. Modify the `data-ad-client` parameter with the user's publisher ID and the `data-ad-host` parameter with the platform's host ID. Control over ad settings determines tag placement, user preferences may be collected for tailored tagging. `data-ad-slot` is needed for non-display ad units. Ensure the correct `data-ad-client` for revenue allocation. Various ad types, including Display, AMP, Auto ads and ads via API, each have specific code examples.\n"],null,["Ad tags\n-------\n\nThe AdSense ad tag enables ad serving and revenue sharing. You need to place the AdSense ad tag on every page where your users can opt-in to monetize their content with AdSense.\n\nHow you approach this step will likely depend on the [ad settings control](/adsense/platforms/transparent/initial-tasks#choose_your_initial_configuration) and ads experience you want to give your users:\n- If you're in control of the ad settings, you can decide which ad types and placements you want to support and add the ad tags to your users' sites as if they were your own sites. You create ad units inside your AdSense account, but modify the data-ad-client and data-ad-host parameters\n- If you're delegating control of the ad settings to your users, you might want to ask your users what their preferences are for ad types and placements (left, right, top, bottom, etc.) and use those preferences to do the tagging. Note that in order to support Native ads, the ad tags require an ad unit ID which you will need to collect from your users.\n\n### Ad tag parameters\n\nThere are two required parameters in the ad tag that you need to modify. These parameters determine ad serving and revenue sharing with your users. Set these parameters to specify the platform's publisher ID and the user's publisher ID. There are other additional parameters that can be modified depending on the ad format used.\n\n| Parameter | Is required? | Description and example |\n|------------------------|--------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `data-ad-client` | Yes | Your user's AdSense for Content publisher ID (string). This value is provided by the user through the [sign up flow](/adsense/platforms/transparent/sign-up-flow). This value is required to initiate revenue sharing. \u003cbr /\u003e For AdSense for content ads, prepend this string with \"ca-\". \u003cbr /\u003e Note that it also appears in the source URL of the script tag under the parameter name `client`. \u003cbr /\u003e Example: `data-ad-client=\"`\u003cvar translate=\"no\"\u003eca-pub-1234\u003c/var\u003e`\"` `src=\".../adsbygoogle.js?client=`\u003cvar translate=\"no\"\u003eca-pub-1234\u003c/var\u003e`&host=ca-host-pub-5678\"` |\n| `data-ad-host` | Yes | This is your platform's host property ID (string). This value identifies your platform's AdSense account and is required to initiate ad serving. \u003cbr /\u003e For AdSense for content ads, prepend this string with \"ca-host-\". \u003cbr /\u003e Note that it also appears in the source URL of the script tag under the parameter name `host`. \u003cbr /\u003e Example: `data-ad-host=\"`\u003cvar translate=\"no\"\u003eca-host-pub-5678\u003c/var\u003e`\"` `src=\".../adsbygoogle.js?client=ca-pub-1234&host=`\u003cvar translate=\"no\"\u003eca-host-pub-5678\u003c/var\u003e`\"` |\n| `data-ad-slot` | No for Display ad units \u003cbr /\u003e Yes for other ad unit formats | This is the ID associated with an ad unit. For Display ad units, this ID is optional, but for other ad unit formats this is a required field. When the ad unit ID is present, settings associated with the ad unit are used during ad serving. During serving, we look for this ad unit ID in both the platform (`data-ad-host`) and child (`data-ad-client`) accounts. This parameter is also used to populate the Ad units report in AdSense (the report will only be populated in the account that the ad unit exists in). |\n| `data-ad-host-channel` | No | This is used for reporting purposes. See the [reporting section](/adsense/platforms/transparent/reporting) for more information. |\n\n**Important:** If the `data-ad-host` parameter is not present in your ad code, AdSense will continue ad serving using the value provided by the `data-ad-client` parameter. However, your the platform account won't receive any impressions in their account and no revenue sharing. You can alternatively use the google-adsense-platform meta tag to ensure your host publisher ID is included in the ad request.\n\nAlso, make sure that you place the correct `data-ad-client` publisher ID in the code tag to avoid attributing revenue to the wrong user.\n\n### Ad code examples\n\nBelow you'll find a code example for each ad type that AFP supports. Learn more about [ad units](https://support.google.com/adsense/answer/9183549) and [Auto ads](https://support.google.com/adsense/answer/9261805) in AdSense.\n\n#### Display ad unit code (responsive)\n\n \u003cscript async\n src=\"//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=\u003cvar translate=\"no\"\u003eca-pub-1234\u003c/var\u003e&host=\u003cvar translate=\"no\"\u003eca-host-pub-5678\u003c/var\u003e\"\n crossorigin=\"anonymous\"\u003e\n \u003c/script\u003e\n \u003cins class=\"adsbygoogle\"\n style=\"display:block;\"\n data-ad-client=\"\u003cvar translate=\"no\"\u003eca-pub-1234\u003c/var\u003e\"\n data-ad-host=\"\u003cvar translate=\"no\"\u003eca-host-pub-5678\u003c/var\u003e\"\n data-ad-format=\"auto\"\u003e\n \u003c/ins\u003e\n \u003cscript\u003e\n (adsbygoogle = window.adsbygoogle || []).push({});\n \u003c/script\u003e\n\n#### Display ad unit code (fixed size)\n\n \u003cscript async\n src=\"//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=\u003cvar translate=\"no\"\u003eca-pub-1234\u003c/var\u003e&host=\u003cvar translate=\"no\"\u003eca-host-pub-5678\u003c/var\u003e\"\n crossorigin=\"anonymous\"\u003e\n \u003c/script\u003e\n \u003cins class=\"adsbygoogle\"\n style=\"display:inline-block;width:728px;height:90px\"\n data-ad-client=\"\u003cvar translate=\"no\"\u003eca-pub-1234\u003c/var\u003e\"\n data-ad-host=\"\u003cvar translate=\"no\"\u003eca-host-pub-5678\u003c/var\u003e\"\u003e\n \u003c/ins\u003e\n \u003cscript\u003e\n (adsbygoogle = window.adsbygoogle || []).push({});\n \u003c/script\u003e\n\n#### Display AMP ad unit (responsive)\n\nThe following code needs to be placed in the `\u003chead\u003e` of the page: \n\n \u003cscript async custom-element=\"amp-ad\" src=\"https://cdn.ampproject.org/v0/amp-ad-0.1.js\"\u003e\u003c/script\u003e\n\nAnd this is the snippet for the ad unit, placed in the `\u003cbody\u003e`: \n\n \u003camp-ad\n width=\"100vw\"\n height=\"320\"\n type=\"adsense\"\n data-ad-client=\"\u003cvar translate=\"no\"\u003eca-pub-1234\u003c/var\u003e\"\n data-ad-host=\"\u003cvar translate=\"no\"\u003eca-host-pub-5678\u003c/var\u003e\"\n data-ad-slot=\"\"\n data-auto-format=\"rspv\"\n data-full-width=\"\"\u003e\n \u003cdiv overflow=\"\"\u003e\n \u003c/amp-ad\u003e\n\n#### Display AMP ad unit (fixed size)\n\nThe following code needs to be placed in the `\u003chead\u003e` of the page: \n\n \u003cscript async custom-element=\"amp-ad\" src=\"https://cdn.ampproject.org/v0/amp-ad-0.1.js\"\u003e\u003c/script\u003e\n\nAnd this is the snippet for the ad unit, placed in the `\u003cbody\u003e`: \n\n \u003camp-ad\n layout=\"fixed\"\n width=\"300\"\n height=\"600\"\n type=\"adsense\"\n data-ad-client=\"\u003cvar translate=\"no\"\u003eca-pub-1234\u003c/var\u003e\"\n data-ad-host=\"\u003cvar translate=\"no\"\u003eca-host-pub-5678\u003c/var\u003e\"\u003e\n \u003c/amp-ad\u003e\n\n#### Auto ads\n\nIdeally, the following ad tag is placed in the `\u003chead\u003e` element, or as high up the page as possible. \n\n \u003cscript async\n src=\"//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=\u003cvar translate=\"no\"\u003eca-pub-1234\u003c/var\u003e&host=\u003cvar translate=\"no\"\u003eca-host-pub-5678\u003c/var\u003e\"\n crossorigin=\"anonymous\"\u003e\n \u003c/script\u003e\n\n### Ads via the ad placement API\n\nThe ad placement API currently supports interstitial and rewarded ads. Read the [Ad Placement API developer documentation](/ad-placement) to learn about how to implement the API and customise it.\n\nAdSense for Platforms is supported for these formats (currently only for web traffic). The only requirement is that the `data-ad-host` parameter is included in the main ad tag. See the example below. \n\n \u003cscript async\n src=\"//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=\u003cvar translate=\"no\"\u003eca-pub-1234\u003c/var\u003e&host=\u003cvar translate=\"no\"\u003eca-host-pub-5678\u003c/var\u003e\"\n crossorigin=\"anonymous\"\u003e\n \u003c/script\u003e\n \u003cscript\u003e\n window.adsbygoogle = window.adsbygoogle || [];\n var adBreak = adConfig = function(o) {adsbygoogle.push(o);}\n \u003c/script\u003e"]]