Storing Variables in game server location for browser (Universal Variable)

Howdy, I was wondering if there were any ways to detect and store variables from individual game instances on browsers, for example;
If two different people playing from two different locations were to interact with an event with a +1 to variable command, then were to see that the variable equals to 2. Note I'm not talking about multiplayer function ala Alpha.net if I can help it.

Just simply being able to take a variable from different people and store it to the main server were the game is being hosted and being able to show that variable to everyone. Plugin or scriptcalls or anything.
If you're trying to collect statistical data, like how many players beat the game, or what are the high scores and so on, then yes, this is easy.

JavaScript:
let url = "postHighScore"; // this is the address on the host server where you want to post your high score.
let data = $gameVariables.value(13); // send variable #0013 to server

let xhr = new XMLHttpRequest();
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function() {
    if (xhr.readyState !== 4) {
        return;
    }
    if (xhr.status === 200) {
        // data was successfully sent. Do something here.
    } else {
        // an error occurred. What to do?
    }
};
xhr.send(JSON.stringify(data));

This is even easier if you use the Fetch API (I don't know if MV supports the Fetch API, but if the game is going to be hosted on a server anyway, then only the player's browser matters):
JavaScript:
let url = "postHighScore"; // this is the address on the host server where you want to post your high score.
let data = $gameVariables.value(13); // send variable #0013 to server

fetch(url, {
    method: "post",
    headers: {
        "Accept": "application/json",
        "Content-Type": "application/json"
    },
    body: JSON.stringify(data)
}).then(response => {
    if (response.ok) {
        // data was successfully sent. Do something here.
    } else {
        // an error occurred. What to do?
    }
});

To retrieve the data from the server:
JavaScript:
let url = "getHighScore"; // this is the address on the host server from where you can get your high score.

let xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function() {
    if (xhr.readyState !== 4) {
        return;
    }
    if (xhr.status === 200) {
        let data = JSON.parse(xhr.responseText);
        $gameVariables.setValue(14, data); // store data in variable #0014
    } else {
        // an error occurred. What to do?
    }
};
xhr.send(JSON.stringify(data));

Or using the Fetch API:
JavaScript:
let url = "getHighScore"; // this is the address on the host server from where you can get your high score.

fetch(url).then(response => {
    if (response.ok) {
        let data = JSON.parse(xhr.responseText);
        $gameVariables.setValue(14, data); // store data in variable #0014
    } else {
        // an error occurred. What to do?
    }
});

Of course, you'll need to program your server, so it actually supports those postHighScore and getHighScore routes.
First, you'd use JavaScript to detect the event in the browser and then send the updated variable value to the server using AJAX. On the server side, you'd have a script (PHP, Node.js, etc.) that would receive the value, update the server-side variable, and then store it in a database or some other persistent storage. When a new user loads the game, you'd fetch the current value of the variable from the server and display it in their browser. You can achieve this by making another AJAX request to the server and then updating the displayed value accordingly.
If you're trying to collect statistical data, like how many players beat the game, or what are the high scores and so on, then yes, this is easy.

JavaScript:
let url = "postHighScore"; // this is the address on the host server where you want to post your high score.
let data = $gameVariables.value(13); // send variable #0013 to server

let xhr = new XMLHttpRequest();
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function() {
    if (xhr.readyState !== 4) {
        return;
    }
    if (xhr.status === 200) {
        // data was successfully sent. Do something here.
    } else {
        // an error occurred. What to do?
    }
};
xhr.send(JSON.stringify(data));

This is even easier if you use the Fetch API (I don't know if MV supports the Fetch API, but if the game is going to be hosted on a server anyway, then only the player's browser matters):
JavaScript:
let url = "postHighScore"; // this is the address on the host server where you want to post your high score.
let data = $gameVariables.value(13); // send variable #0013 to server

fetch(url, {
    method: "post",
    headers: {
        "Accept": "application/json",
        "Content-Type": "application/json"
    },
    body: JSON.stringify(data)
}).then(response => {
    if (response.ok) {
        // data was successfully sent. Do something here.
    } else {
        // an error occurred. What to do?
    }
});

To retrieve the data from the server:
JavaScript:
let url = "getHighScore"; // this is the address on the host server from where you can get your high score.

let xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function() {
    if (xhr.readyState !== 4) {
        return;
    }
    if (xhr.status === 200) {
        let data = JSON.parse(xhr.responseText);
        $gameVariables.setValue(14, data); // store data in variable #0014
    } else {
        // an error occurred. What to do?
    }
};
xhr.send(JSON.stringify(data));

Or using the Fetch API:
JavaScript:
let url = "getHighScore"; // this is the address on the host server from where you can get your high score.

fetch(url).then(response => {
    if (response.ok) {
        let data = JSON.parse(xhr.responseText);
        $gameVariables.setValue(14, data); // store data in variable #0014
    } else {
        // an error occurred. What to do?
    }
});

Of course, you'll need to program your server, so it actually supports those postHighScore and getHighScore routes.
hi, don't know if it's the right spot to ask this, but: can I make a browser global variable existing only client-side to be equal to a game variable?
Let's say I have a website where people can write their name on a text window.
I encode their string into the variable

Code:
name.string = input text string

now I'd like the game variable 01 (the game is played within the browser) to be equal to that text.

something like

Code:
$gameVariables. setValue(1, name.string)

How can I make it? Thank you

Original thread: https://forums.rpgmakerweb.com/threads/storing-variables-in-game-server-location-for-browser-universal-variable.148475/