使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
展示激励广告
此示例演示了如何使用 Google 发布商代码 (GPT) 库请求和呈现激励广告。激励广告格式可让应用和网站用户在观看广告后获得奖励。如需详细了解激励广告,请访问 Google Ad Manager 帮助中心。
您可以使用以下 GPT 事件展示激励广告以及与之互动:
在本例中,我们使用一个简单的模态对话框来提示用户观看激励广告,并在用户观看完广告后显示奖励。实际上,发布商有责任实现自己的接口来完成这些任务。
使用说明
为确保提供最佳用户体验,系统只会在正确支持激励广告格式的页面上请求此类广告。因此,defineOutOfPageSlot()
可能会返回 null
;您应检查是否存在这种情况,以确保不会执行任何不必要的工作。目前,只有在缩放不起作用的针对移动设备进行了优化的网页上才支持激励广告。通常,这意味着发布商在网页的 <head>
中包含 <meta name="viewport"
content="width=device-width, initial-scale=1">
或类似内容。
激励广告会生成自己的广告位。与其他广告类型不同,您不必为激励广告定义 <div>
。当广告填充时,激励广告会自动创建自己的容器并将其插入网页中。
实现示例
查看演示
[null,null,[],[],[],null,["# Display a rewarded ad\n=====================\n\nThis example demonstrates using the Google Publisher Tag (GPT) library to\nrequest and render a rewarded ad. Rewarded ad formats let app and web users\nreceive rewards for viewing ads. Learn more about rewarded ads in the\n[Google Ad Manager help center](//support.google.com/admanager/answer/9116812).\n\nYou can use the following GPT events to display and interact with rewarded ads:\n\n| Event | Fired when... |\n|-------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------|\n| [RewardedSlotClosedEvent](//developers.google.com/publisher-tag/reference#googletag.events.rewardedslotclosedevent) | A rewarded ad slot has been closed. |\n| [RewardedSlotGrantedEvent](//developers.google.com/publisher-tag/reference#googletag.events.rewardedslotgrantedevent) | A reward has been granted for viewing an ad. |\n| [RewardedSlotReadyEvent](//developers.google.com/publisher-tag/reference#googletag.events.rewardedslotreadyevent) | A rewarded ad slot is ready to be displayed. |\n| [RewardedSlotVideoCompletedEvent](//developers.google.com/publisher-tag/reference#googletag.events.rewardedslotvideocompletedevent) | A rewarded ad slot has finsihed playing a video. |\n\nFor the purpose of this example, a simple modal dialog is used to both prompt\nthe user to view the rewarded ad and to display the reward upon completion. In\npractice, it is the responsibility of the publisher to implement their own\ninterface to accomplish these tasks.\n| **Important:** Before you display a rewarded ad, you must comply with the [policies for ad units that offer rewards](//support.google.com/admanager/answer/7496282) and obtain user consent.\n\nUsage notes\n-----------\n\n- **To ensure an optimal user experience, rewarded ads are only requested on\n pages that properly support the format.** Because of this,\n `defineOutOfPageSlot()` may return `null`; you should check for this case to\n ensure you're not doing any unnecessary work. Currently, rewarded ads are\n only supported on mobile optimized pages where zoom is neutral. Typically\n this means the publisher has `\u003cmeta name=\"viewport\"\n content=\"width=device-width, initial-scale=1\"\u003e` or similar in the `\u003chead\u003e`\n of the page.\n\n- **Rewarded ads generate their own ad slot.** Unlike other ad types, it's not\n necessary to define a `\u003cdiv\u003e` for rewarded ads. Rewarded ads automatically\n create and insert their own container into the page when an ad fills.\n\nSample implementation\n---------------------\n\n[View demo](https://googleads.github.io/google-publisher-tag-samples/display-rewarded-ad/js/demo.html) \n\n### JavaScript\n\nLoading...\n----------\n\nLoading...\n----------\n\n[Improve this sample](https://github.com/googleads/google-publisher-tag-samples/tree/main/dist/display-rewarded-ad/js) [Report an issue](https://github.com/googleads/google-publisher-tag-samples/issues/new?labels=documentation&template=sample-feedback.md&title=Sample+feedback%3A+display-rewarded-ad/js)\n\n### TypeScript\n\nLoading...\n----------\n\nLoading...\n----------\n\n[Improve this sample](https://github.com/googleads/google-publisher-tag-samples/tree/main/dist/display-rewarded-ad/ts) [Report an issue](https://github.com/googleads/google-publisher-tag-samples/issues/new?labels=documentation&template=sample-feedback.md&title=Sample+feedback%3A+display-rewarded-ad/ts)"]]