Wix Tutorial: Show content based on users country

Found another solution as well! Feel free to use it, worked properly on my end. USed the service https://ipinfo.io/json to retrieve the user location

import {fetch} from 'wix-fetch';

$w.onReady(function () {
    fetch('https://ipinfo.io/json') // third party serive via which you get a JSON with data (includin country)
    .then(response => response.json())
    .then(data => {
        //Check if user country is United Kingdom (GB is the country code for the United Kingdom)
        if(data.country === "GB") { 
            //assign the UK Phone number to a text element
            $w("#phoneText").text = "UK Phone Number: +44 0000 0000";
            //Check if user country is United States (US is the country code for the United States)
        } else if(data.country === "US") { 
        //assign the UK Phone number to a text element
            $w("#phoneText").text = "US Phone Number: +1 0000 0000";
        }
    })
    .catch(error => {
        console.error("Error retrieving IP information", error);
    });
});


1 Like