amp.dev icon indicating copy to clipboard operation
amp.dev copied to clipboard

Geo override is broken, or docs are conflicting & incomplete

Open ptim opened this issue 2 years ago • 1 comments

📖 Missing or Out-of-Date Documentation

(I'm unsure whether the geo override functionality works at present...)

Problem

It's unclear how to set geo overrides for testing geolocation based consent flows, and I'm not sure if either of the following docs are correct, as I haven't managed to get it to work...

Short version:

  • opt in to to either the experimental or beta channel (it's unclear which, and they're mutually exclusive)
  • add #amp-geo=gb to coerce amp-geo to read GB

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

https://amp.dev/documentation/examples/user-consent/geolocation-based_consent_flow/?format=websites

Adding #amp-geo=XX to the document url forces the country to appear as the country XX. This allows you to test without having to VPN to a country. For security reasons, to prevent sharing of geo-spoofing urls, this feature is only available to users who have enabled the Experimental Channel or who are testing locally (i.e., amp-geo.js is served in development mode via amp serve).

https://amp.dev/documentation/components/amp-geo/

^ would be helpful if this page linked to the example above (first quote), and also mentioned how to set us-ca. A note that the example is heavily commented would be ideal.

I'm guessing that the override case is unimportant: it's inconsistent.

Enable an experiment for a particular document

Document can choose to opt in a certain experiments. To do that, place a meta tag of the amp-experiments-opt-in name in the head of the HTML document before your AMP script (https://cdn.ampproject.org/v0.js). Its content value is a comma-separated string of experiment IDs to opt in. https://amp.dev/documentation/guides-and-tutorials/learn/experimental/?format=websites

^ It's unclear whether this is a supported approach for overriding geo... (there's no experiment listed that relates to amp-geo, and various attempted values have failed)

Also, it seems that channel opt-ins are stored in a cookie __Host-AMP_OPT_IN, rather than localStorage:

Experiment opt-ins are saved to localStorage and only enables the experiment on AMP pages served from the current domain.

https://amp.dev/documentation/guides-and-tutorials/learn/experimental/?format=websites

The playground example doesn't work as expected

According comments in the playground example:

Given I've opted to experiments (also tried beta) in at https://cdn.ampproject.org/experiments.html And https://amp-dev.cdn.ampproject.org/experiments.html When I visit https://amp.dev/documentation/examples/user-consent/geolocation-based_consent_flow/#amp-geo=us%20us-ca Then I should see <html ⚡ class="amp-geo-group-usca amp-iso-country-us">

Actually, I still see amp-iso-country-au

Local tests

Given that I've visited https://cdn.ampproject.org/experiments.html and clicked experiments channel: ON (also tried beta) When I visit a local AMP page: localhost/my-article/?amp=true#amp-geo=us%20us-ca And that page loads AMP scripts from https://cdn.ampproject.org/v0.js And that page has <meta name="amp-experiments-opt-in" content="amp-geo"> prior to scripts And that page has amp-geo and amp-consent configured as below Then I expect to see <html ⚡ class="amp-geo-group-iubenda amp-iso-country-us">

<amp-geo layout="nodisplay">
    <script type="application/json">
        {
            "ISOCountryGroups": {
                "iubenda": ["preset-eea", "preset-us-ca", "BR", "unknown"]
            }
        }
    </script>
</amp-geo>
<amp-consent id="iubenda" layout="nodisplay" type="iubenda">
    <script type="application/json">
        {
            "consentInstanceId": "iubenda-consent",
            "consentRequired": false,
            "geoOverride": {
                "iubenda": {
                    "consentRequired": true,
                    "promptUISrc": "https://localhost/amp-consent-iframe.html#amp-geo=us",
                    "postPromptUI": "post-consent-ui"
                }
            }
        }
    </script>
</amp-consent>

Actually, I see: <html ⚡ class="amp-geo-no-group amp-iso-country-au">

ptim avatar Sep 28 '22 03:09 ptim

Cross posted https://github.com/ampproject/amphtml/issues/38493

ptim avatar Oct 13 '22 01:10 ptim