Skip to content

Instantly share code, notes, and snippets.

@AlexWebLab
Forked from panoply/geoip.js
Created August 20, 2018 03:04
Show Gist options
  • Save AlexWebLab/31303decd254344d359edd86dce1a189 to your computer and use it in GitHub Desktop.
Save AlexWebLab/31303decd254344d359edd86dce1a189 to your computer and use it in GitHub Desktop.
GeoIP Redirect using javascript

GeoIP Redirection

Redirect traffic to another subdomain or URL. This specific .js redirects visitors to country specific website. If you're on a SaaS system or don't have access to backend this is the bare minimal javascript you would need to execute to get an efficient Geographical redirections. This is especially helpful with Shopify stores.

Thanks goes to @nekudo for the GeoIP service.

For best results use in the <head> after your <meta> but before your CSS

<script>
function geo(a) {
switch (a.country.code)
{
case "SE": // Redirect is visitor from Sweden
case "NO": // Redirect is visitor from Norway
case "DK": // Redirect is visitor from Denmark
window.location = "https://se.brixtol.com" + window.location.pathname; // edit for your URL
break;
default:
return null;
}
}
</script>
<script src="https://geoip.nekudo.com/api?callback=geo"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment