AMP Conf 2019. April 17/18. Tokyo.
  • websites

Basic User Consent Flow


Users today want additional control over their online experience. Additionally, publishers are faced with a variety of different demands on how they provide notice and choice to their users - from vendor policies to evolving legal requirements. The open source AMP Project is working to give publishers and tech vendors tools to implement their preferred user controls and to support their varied individual compliance requirements on their AMP pages.

This page demonstrates how a basic blocking consent flow can be built, which would just show a simple blocking popup with an accept and reject button. On reject some content in the page will be blocked.

The consent is saved to localstorage - after accepting/rejecting it once you will only get the popup dialog again after deleting the localstorage content for this host, for example via Chrome Dev Tools.


Import the consent component in the header.

<script async custom-element="amp-consent" src=""></script>

Basic usage

The amp-consent component allows to specify the required user consent for this page. A CORS endpoints can be specified via the checkConsentHref attribute. The amp-consent component will check via a POST request if the consent UI needs to be shown. The response should look like this:

    "promptIfUnknown": boolean (true/false)

It is possible, to re-trigger the consent dialog using the myConsent.prompt() action. One use case for this is giving users the option to change their settings after consent dialog has been dismissed. For this to work, the post consent UI needs to be specified in the amp-consent JSON config: "promptUI": "consentDialog".

<amp-consent id="myUserConsent"
  <script type="application/json">
      "consents": {
        "consent1": {
          "checkConsentHref": "",
          "promptUI": "consentDialog"
      "postPromptUI": "post-consent-ui"
  <div class="popupOverlay"
    <div class="consentPopup">
      <div class="dismiss-button"
      <p>This is an important message requiring you to make a choice.</p>
      <p>This is some more information about this choice. Here's a list of items related to this choice.</p>
      <amp-list height="132"
        <template type="amp-mustache">
      <button on="tap:myUserConsent.accept">Accept</button>
      <button on="tap:myUserConsent.reject">Reject</button>
  <div id="post-consent-ui">
    <button on="tap:myUserConsent.prompt()">Update Consent</button>

Use data-block-on-consent attribute to block AMP components until consent is given.

Individual AMP components can override blocking behavior and implement blocking logic themselves.

Here is an image which is blocked until consent is given:

<amp-img data-block-on-consent

Ads can also be blocked until consent is given, but ad networks can implement own behavior

(e.g. default to non-personalized ads without consent, as seen

documented here for Doubleclick). Note that you may see the same ad when accepting or rejecting consent for this specific example and that's because the example doesn't use personalized information even when accepting consent.

Here is an example of amp-ad depending on amp-consent:

<amp-ad data-block-on-consent
Need further explanation?

If the explanations on this page don't cover all of your questions feel free to reach out to other AMP users to discuss your exact use case.

Go to Stack Overflow
An unexplained feature?

The AMP project strongly encourages your participation and contributions! We hope you'll become an ongoing participant in our open source community but we also welcome one-off contributions for the issues you're particularly passionate about.

Edit sample on GitHub