How to display the learnious games?

Not so complicated

  • The games are hosted on our server and are called on your pages through iframes or CURL.
  • Some variables allow you to customize the games.
  • At the end of a game, our system sends a set of metrics to your server.
All the further samples are for iframes. The last one is a CURL integration example.

Basic use

Use the following code to display the games.

The PATH_TO_A_DEDICATED_SCRIPT will be a dedicated php script on our server.

<iframe src='[PATH_TO_A_DEDICATED_SCRIPT]?t=[YOUR TOKEN]&game_id=2' width='900px' height='600px'></iframe>

Variables

The token (t)

[STRING] (mandartory)

The token is unique string. It will be sent to you by our services.

<iframe src='[PATH_TO_A_DEDICATED_SCRIPT]?t=[YOUR TOKEN]&game_id=2' width='900px' height='600px'></iframe>

game_id

[INT] (mandartory)

For our games to be displayed, we need to know which game you want. This is done via the game_id

<iframe src='[PATH_TO_A_DEDICATED_SCRIPT]?t=[YOUR TOKEN]&game_id=2' width='900px' height='600px'></iframe>

nb_questions

[INT] (optional)

By default most of our games are set to 20 questions. It's possible to set fewer or more questions.

<iframe src='[PATH_TO_A_DEDICATED_SCRIPT]?t=[YOUR TOKEN]&game_id=2&nb_questions=10' width='900px' height='600px'></iframe>

time_to_play

[INT] (optional)

The game duration in seconds. By default most of our games have a duration of 180s. You can change this duration.

<iframe src='[PATH_TO_A_DEDICATED_SCRIPT]?t=[YOUR TOKEN]&game_id=2&time_to_play=60' width='900px' height='600px'></iframe>

payload

[STRING] (optional)

We don't want you to give us names, ids or whatever data on your users. Privacy does matter.
On the other hand you need to send and receive data to and from the games to store the user's performance properly.
This is achieved by the "payload" var. This var can encapsulate encrypted data on your users in Base64 or whatever other system you want. It will be forwarded to you at the end of the game as it was sent at the beginning. We won't try to read or modify this var.

<iframe src='[PATH_TO_A_DEDICATED_SCRIPT]?t=[YOUR TOKEN]&game_id=2&payload=dXNlcl9pZD0xMiZ0ZXN0PTMw' width='900px' height='600px'></iframe>

save_url

[STRING] (optional)

An absolute path to your save script.
This script will be called with a set of POST variables at the end of the game.

<iframe src='[PATH_TO_A_DEDICATED_SCRIPT]?t=[YOUR TOKEN]&game_id=2&save_url=https://www.yoursite.com/save_play.php' width='900px' height='600px'></iframe>

The vars sent back to you in POST to the provided "save_url" will be the following :

  • payload [STRING]
    The var as you gave it.
  • game_id [INT]]
    The game id :)
  • score [INT]
    The result of the game.
  • percent_success [INT]
    The percentage of correct answers given by the user during the game.

CURL

Here is a base code to display our games through php CURL.


$game_url = '[PATH_TO_A_DEDICATED_SCRIPT]?t=[YOUR TOKEN]&game_id=2';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => ($game_url),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET'
));

$headers = array();
$headers[] = 'Content-Type:application/json';
$headers[] = 'Access-Control-Request-Method: GET';
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
	echo 'cURL Error #:' . $err;
	die();
}
// The display, in a position:relative dom element.
echo '<div style="position:relative;">';
echo $response;
echo '</div>';