Skip to content

Instantly share code, notes, and snippets.

@panoply
Created September 9, 2016 14:05
Show Gist options
  • Save panoply/ef3396e3f216d8a231d9a6440e324d1b to your computer and use it in GitHub Desktop.
Save panoply/ef3396e3f216d8a231d9a6440e324d1b 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>
@DOVICHI
Copy link

DOVICHI commented Dec 12, 2018

Does not work for me. Do i need to register the domain anywhere?

@Phthalo929
Copy link

Yeah, doesn't work for me either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment