Redirecting Users by Country

A common use-case for geolocation is to redirect users based on their country. With Ipregistry you can, for example, redirect a user to a country-specific store or Web page of your international Website:

const MAPPINGS = {
    FR: '',
    DE: '',
    US: '',

    .then(function(response) { return response.json(); })
    .then(function(payload) {
        const userCountryCode = payload['location']['country']['code'];
        let redirectionUrl = MAPPINGS[userCountryCode];

        if (!redirectionUrl) {
            redirectionUrl = ''

        window.location.href = redirectionUrl;
    }).catch(function (error) {
    	console.error("Handle errors here", error);

The code snippet above redirects users from France to, users from Germany to and users from the United States of America to Otherwise, the redirection fallbacks to

You can easily find the ISO 3166-1 alpha-2 code associated with a country on Wikipedia.