我想向我的AMP静态网站添加cookie同意。我想利用amp-story-consent
可以提供给我的模式对话框。我研究了各种示例,也许最完整的示例是这样:
https://playground.amp.dev/?url=https%3A%2F%2Fpreview.amp.dev%2Fdocumentation%2Fexamples%2Fuser-consent%2Fstory_user_consent&format=websites(示例文档https://amp.dev/documentation/examples/user-consent/story_user_consent/?referrer=ampbyexample.com)
我的问题是我只想显示JSON代码段中定义的标题/消息/供应商
<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>
加上“接受”和“拒绝”按钮。经过Cookie同意,我实际上并没有任何故事页面或任何故事书挡,但是AMP验证规则似乎是必需的。那是一个问题。操场上显示了“拒绝/接受”按钮对,我想要“拒绝/接受”对,但是我看不到可以在哪里定义。
在amp-consent
裸露的文档中有一些按钮(请参见https://amp.dev/documentation/components/amp-consent/的“同意配置”):
<div id="consent-ui">
<button on="tap:consent-element.accept" role="button">Accept</button>
<button on="tap:consent-element.reject" role="button">Reject</button>
<button on="tap:consent-element.dismiss" role="button">Dismiss</button>
</div>
有人有例子或指导吗?
请注意,https://amp.dev/documentation/components/amp-consent/具有此示例代码段。上面写着“示例:在AMP故事上显示提示用户界面”
<amp-consent layout="nodisplay" id="consent-element">
<script type="application/json">
{
"consents": {
"my-consent": {
"checkConsentHref": "https://amp.dev/documentation/examples/api/get-consent",
"promptUI": "consent-ui"
}
}
}
</script>
<amp-story-consent id="consent-ui" layout="nodisplay">
<script type="application/json">
{
“title”: "My title",
“message”: "My example message.",
“vendors”: ["Item 1", "Item 2", "Item 3", "Item 4"]
}
</script>
</amp-story-consent>
</amp-consent>
如何使它工作? (正如我提到的,我也没有如代码段所示的任何故事页面或任何故事书挡。)
答案 0 :(得分:1)
您不能在amp-story-consent
之外使用amp-story
,因为amp-story-page
必须具有一定数量的{{1}}元素。