0

我想向我的 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>

How to get that working? (As I mentioned I don't have any story pages or any story bookend as the snippet suggests as well).

4

1 回答 1

1

You cannot use amp-story-consent outside of an amp-story, which must have some number of amp-story-page elements.

于 2020-05-21T23:17:58.607 回答