Hi,
Is it possible to get the country of the user and store it in a variable?
I know it's possible to make web calls using javascript but I'm not sure whether returned results (for example JSON) can be stored (and parsed) within the tour.
Thanks!
Roland
Save User Country
Yes, you can do this for example with https://ip-api.io/
Just put the following into a textbox, and add a text variable "country". You will also need an API key from ip-api.io. Then replace "{your api key}" with your key.
Just put the following into a textbox, and add a text variable "country". You will also need an API key from ip-api.io. Then replace "{your api key}" with your key.
Code: Select all
javascript:"";
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
var r=JSON.parse(xhttp.responseText);
player.setVariableValue("country",r.country_code);
}
};
xhttp.open("GET", "https://ip-api.io/json?api_key={your api key}", true);
xhttp.send();
MfG, Thomas