用户同意
简介
此示例展示了如何在 AMP Stories 中集成 amp-consent
,以便为用户提供对数据共享和 Cookie 的控制。
设置
导入 amp-story
扩展以创建 AMP Story...
<script async custom-element="amp-story" src="https://cdn.ampproject.org/v0/amp-story-1.0.js"></script>
... 以及 amp-consent
扩展。
<script async custom-element="amp-consent" src="https://cdn.ampproject.org/v0/amp-consent-0.1.js"></script>
在 AMP Story 中实施用户同意
amp-consent
将在同意对话框中显示 publisher-logo-src
指定的徽标。
<amp-story standalone
title="Story With User Consent"
publisher="Google"
poster-portrait-src="https://amp.js.cn/img/story_video_dog_cover.jpg"
publisher-logo-src="https://amp.js.cn/static/samples/img/amp_logo_pink.svg">
amp-consent
组件支持通过 checkConsentHref
属性指定 CORS 端点,该组件通过 POST 请求查询该端点,以确定是否需要显示为其指定的同意 UI。响应应如下所示
{ "consentRequired": boolean (required), "consentStateValue": enum (accepted/rejected/unknown) (optional), "consentString": string (optional), "expireCache": boolean (default false), }
响应将指示是否需要显示同意。如果需要显示,则会显示 id 为 promptUI
的元素。对于 AMP Stories,您可以在嵌套的 amp-story-consent
元素中指定同意标题、消息和供应商列表。
<amp-consent id="myConsent" layout="nodisplay">
<script type="application/json">
{
"consents": {
"myConsent": {
"consentInstanceId": "my-amp-story-consent",
"consentRequired": "remote",
"checkConsentHref": "/documentation/examples/api/get-consent",
"promptUI": "consentUI"
}
}
}
</script>
<amp-story-consent id="consentUI" layout="nodisplay">
<script type="application/json">
{
"title": "Headline",
"message": "This is some more information about this choice. Here's a list of items related to this choice.",
"vendors": ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8", "Item 9", "Item 10"]
}
</script>
</amp-story-consent>
</amp-consent>
演示:amp-story
中的 amp-consent
当故事开始时,同意对话框将显示为覆盖层。
需要进一步解释吗?
如果此页面上的解释未能涵盖您的所有问题,请随时联系其他 AMP 用户,讨论您的具体用例。
前往 Stack Overflow 一个无法解释的功能?AMP 项目强烈鼓励您的参与和贡献!我们希望您能成为我们开源社区的持续参与者,但我们也欢迎您为自己特别关注的问题做出一次性贡献。
在 GitHub 上编辑示例-
由 @sebastianbenz 撰写