That would be fun to build.
For the auto-detection part, it’s possible to do the geoip detection client-side, but you generally need a paid service. I like IPInfo. Keep in mind with all of these services, you’ll get a wide range of accuracies, but country identification is generally decent, though I have not tested this in Africa.
{
"ip": "129.234.192.71",
"hostname": "129.234.192.71.adsl.xtra.co.nz",
"city": "Greerton",
"region": "Bay of Plenty",
"country": "NZ",
"loc": "-37.7254,176.1335",
"org": "AS4771 Spark New Zealand Trading Ltd.",
"postal": "3142",
"timezone": "Pacific/Auckland"
}
There is a very slight delay as well in a client-side setup as you’ll have to hit a 3rd party API, get your data, and then update your UI accordingly.
But here’s a crude demo and cloneable to show the functionality and implementation code ( codepen at the bottom ).
https://webflow-forms-demo.webflow.io/special/ip-info
For a professional implementation, I prefer to build a reverse proxy setup through Cloudflare, which can be configured do geo-routing, or to automatically deliver the GeoIP information as a response header.
Unfortunately client-side JS can’t access response headers, so you need to build a worker to extract the JS info and embed it into the page e.g. as a META or script block. In advanced situations, you can build this out so that your elements and sections are tagged with custom attributes by country, and you can then have them automatically “gated” server-side.
Keep in mind that gating your content will mess with Googlebot. You may want a default “show everything” behavior for bots, or a specific configuration for out-of-region countries.
Drop me a message if you need some professional dev work done on this, looks like a fun project.