Do you build things with AMP? Fill out the new AMP Developer Survey!
  • websites

Advanced 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 more advanced blocking consent flow can be built. It will show accept and reject buttons, which on click will reveal more information, like a list of used 3rd parties on user acceptance, or a general data usage notice on user rejection.

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>

for this example we use amp-ad as well as...

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

... amp-list together with...

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

... amp-mustache.

<script async custom-template="amp-mustache" src=""></script>

Basic usage

The amp-consent component allows you to specify the required user consent for this page using the required consentRequired flag. A CORS endpoint can be specified via the checkConsentHref attribute which will be checked via a POST request. The response should look like this:

  "consentRequired": boolean (required),
  "consentStateValue": enum (accepted/rejected/unknown) (optional),
  "consentString": string (optional),
  "expireCache": boolean (default false),

The response will indicate if the element with the id given in promptUI will be displayed. amp-consent will first check localstorage for an existing consent decision and use it if present. Otherwise it will show the promptUi, if configured and consentRequired is true. If consentRequired is set to false, `amp-consent will immediately unblock all elements.

<amp-consent id="myConsent"
  <script type="application/json">
      "consentInstanceId": "advanced-consent",
      "consentRequired": "remote",
      "checkConsentHref": "/documentation/examples/api/get-consent",
      "promptUI": "consentDialog",
      "postPromptUI": "post-consent-ui"
  <div class="lightbox"
    <div class="lightbox-content">
      <div class="dismiss-button"
      <div class="message">
        <p>This is an important message requiring you to make a choice.</p>
      <div id="choice">
        <button on=",choice1.hide">Choice 2</button>
      <div id="choice1"
        <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:myConsent.accept">Confirm</button>
      <div id="choice2"
        <p>This is some more information about this choice.</p>
        <button on="tap:myConsent.reject">Confirm</button>
  <div id="post-consent-ui">
    <button on="tap:myConsent.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

このページの説明でご質問のすべてを解消できない場合は、あなたの実際の使用事例について他の AMP ユーザーに問い合わせて話し合ってください。

Stack Overflow にアクセスする

AMP プロジェクトでは皆さんの参加と貢献を強くお勧めしています!当社はオープンソースコミュニティに継続的にご参加いただくことを希望しますが、特に熱心に取り組んでいる問題があれば1回限りの貢献でも歓迎します。

GitHub でサンプルを編集する