amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

amp-geo doesn't create groups for unknown countries

Open QES opened this issue 8 years ago • 3 comments

Looking at amp-geo as part of my GDPR work I was trying to show something to people outside of the EEA, I have a amp-geo that looks like:

<amp-geo layout="nodisplay" class="sm_geo" >
	<script type="application/json">
			{
			  "ISOCountryGroups": {
				"eea": [ "at", "be", "bg", "cy", "cz", "de", "dk", "ee", "es", "fi", "fr",
				"gb", "uk", "gr", "hr", "hu", "ie", "is", "it", "li", "lt", "lu", "lv", "mt", "nl",
				"no", "pl", "pt", "ro", "se", "si", "sk"],
				"main": [ "at", "be", "bg", "cy", "cz", "de", "dk", "ee", "es", "fi", "fr",
				"gb", "uk", "gr", "hr", "hu", "ie", "is", "it", "li", "lt", "lu", "lv", "mt", "nl",
				"no", "pl", "pt", "ro", "se", "si", "sk", "us", "ca", "ng", "ke", "za", "ua"],
      				"other": [ "unknown" ]
			  }
			}
	</script>
</amp-geo>

I have used Opera and its VPN code to be in a different location and I can see the BODY element showing

But when I remove us from the list of main countries the "other" flag is not set.

ALan

QES avatar May 24 '18 11:05 QES

That's expected behavior. unknown means we couldn't determine the country for the IP address. This lets you decide if you want to treat un-located users as in or out of any given group. There is no mechanism to says 'it didn't match any group'.

I just did a PR to add amp-geo-nogroup if the array of matched groups is empty which should achieve what you need.

jpettitt avatar May 24 '18 15:05 jpettitt

PS:

You'll want to add an amp-geo-pending class to body and use it to suppress notices until amp-geo loads and replaces that class with appropriate groups.

If you need this before the amp-geo-no-group PR makes it to production you can use

:not(.amp-geo-group-eea) .foo { ... }

jpettitt avatar May 24 '18 18:05 jpettitt

Thanks John - that all makes sense. I think the problem is the examples confuse by having 'unknown' given a name that looks like a default when it isn't the default is set in the css https://www.ampproject.org/docs/reference/components/amp-geo

amp-geo-nogroup would do the trick

the :not work around might well solve the problem - thanks for the idea.

QES avatar May 25 '18 10:05 QES