• websites

Geolocation-based Consent Flow


Sometimes is necessary to ask only users from specific countries for consent. This sample demonstrates how you can use amp-consent together with amp-geo to achieve this. In this sample we'll build a consent dialog that will only show for users from the EU.


We need to import both, the amp-consent ...

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

... and the amp-geo extension.

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

Setting up amp-geo

First we need to setup the amp-geo extension. We'll use the present eea which includes all countries of the European Economic Area.

<amp-geo layout="nodisplay">
  <script type="application/json">
      "ISOCountryGroups": {
        "eu": ["preset-eea"]

We define a basic consent flow, similar to this sample. he flow should only trigger for users in the EU, so we set the flag: "promptIfUnknownForGeoGroup": "eu".

<amp-consent id="myUserConsent"
  <script type="application/json">
      "consents": {
        "eu": {
          "promptIfUnknownForGeoGroup": "eu",
          "promptUI": "myConsentFlow"
      "postPromptUI": "post-consent-ui"
  <div id="myConsentFlow"
    <div class="consentPopup">
      <div class="dismiss-button"
      <p>This is an important message requiring you to make a choice if you're based in the EU.</p>
      <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>


You can test different behaviors by appending custom country codes to the URL and enabling the dev-channel here, for example:

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