How to construct AMP cookie consent with the help of amp-story-consent?

五迷三道 提交于 2020-06-09 06:01:28

问题


I'd like to add a cookie consent to my AMP static website. I'd like to take advantage of the modal dialog what the amp-story-consent could provide to me. I studied various examples, maybe the most complete is this:

https://playground.amp.dev/?url=https%3A%2F%2Fpreview.amp.dev%2Fdocumentation%2Fexamples%2Fuser-consent%2Fstory_user_consent&format=websites (example documentation https://amp.dev/documentation/examples/user-consent/story_user_consent/?referrer=ampbyexample.com)

My problem is that I only want to display the title / message / vendors defined in the JSON snippet

    <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>

plus an Accept and a Reject button. With a Cookie consent I don't really have any story pages or any story bookend, but the AMP validation rules seems to require it. That's one problem. The playground shows a Decline / Accept button pair, I'd like a Reject / Accept pair but I don't see where this can be defined.

In the bare amp-consent documentation there are buttons (see "Consent configuration" at 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>

Does anyone have an example or guidance?


Note that the https://amp.dev/documentation/components/amp-consent/ has this example snippet. It says "Example: Displays a prompt user interface on an AMP Story"

<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).


回答1:


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



来源:https://stackoverflow.com/questions/61929226/how-to-construct-amp-cookie-consent-with-the-help-of-amp-story-consent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!