Webhook and return values

The brand must transmit the userid to the server where the HTML5 game files are hosted via the Webhook server. Once the game ends, the values of userid and GameResult are returned to the Webhook server. Through the userid, the brand can identify who the game player is and receive the GameResult information of the respective player via the Webhook server. The setup of such a Webhook server must be carried out by the brand itself.

You can use the userid and Webhook to send game-related data to the brand's Webhook server after the game on Brand hosting.

Basic scenario

  1. When a mini-game is launched on the brand’s server, the user ID (userid) is retrieved from the brand’s Webhook server via a GET request and passed to the mini-game execution URL.

  2. The mini-game runs within the web page environment of the brand’s server.

  3. After the game ends, the game score is displayed on the results screen.

  4. The brand’s Webhook server receives game-related data through the Webhook.

  5. Based on the received data, the brand operates its own leaderboard and rewards programme.

Setup process

  1. The brand must set up a Webhook program on their server to receive game result data.

  2. You need to enter the Webhook server’s address in the Installation section of Studio.

  3. Download the game file with the completed setup as a ZIP file.

  4. Copy the ZIP file to the brand server and complete the necessary setup.

  5. The brand applies the received data to their own leaderboard or reward program based on the data transmitted via Webhook.

Instructions on how to apply

When running the mini-game in a web browser, the ‘userid’ parameter and its value must be included using the GET method.

Parameter

Name
Description
Format
Sample

userid

Unique ID generated from the brand's system

Alphanumeric (case-sensitive) + up to 20 digits

T4g4fLTaorjames

Example, Original campaign URL address https://brand.server.com/ The brand's system must call this URL and send the "userid".

https://brand.server.com/?php=userid=T4g4fLTa

After the game, the result value is sent to the brand's Webhook URL

After the game, the result value and various data are received by the brand’s server through the Webhook created by the brand.

Name
Description
Sample

userid

User's unique ID

T4g4fLTa or james

time

Datetime when the game player attempted to play

Unix Timestamp (Milliseconds)

result

Game Score obtained by the game player

3500

playtime

Duration of play by the game player (in seconds)

20

PHP example

Here is a PHP example that receives the result of a mini-game in JSON format and inserts it into a MySQL database.

<?php
// Include the database connection file
require_once "connect.php";

header("Content-Type: application/json");

// Get JSON data from the request
$data = json_decode(file_get_contents("php://input"), true);

// Check if JSON data is valid
if (!$data) {
    http_response_code(400);
    echo json_encode(["error" => "Invalid JSON format"]);
    exit;
}

// Extract values from the JSON payload
$result = $data["result"] ?? null;
$playtime = $data["playtime"] ?? null;
$time = $data["time"] ?? null;
$userid = $data["userid"] ?? null;

// Validate required fields
if ($result === null || $playtime === null || $time === null || $userid === null) {
    http_response_code(400);
    echo json_encode(["error" => "Missing required fields"]);
    exit;
}

try {
    // Save data to MySQL database
    $stmt = $pdo->prepare("INSERT INTO game_results (userid, result, playtime, time) VALUES (:userid, :result, :playtime, :time)");
    $stmt->execute([
        ":userid" => $userid,
        ":result" => $result,
        ":playtime" => $playtime,
        ":time" => $time
    ]);

    // Return success response
    echo json_encode(["message" => "Data saved successfully"]);
} catch (PDOException $e) {
    http_response_code(500);
    echo json_encode(["error" => "Database error"]);
}
?>

SQL

CREATE TABLE game_results (
    id INT AUTO_INCREMENT PRIMARY KEY,
    userid VARCHAR(255) NOT NULL,
    result INT NOT NULL,
    playtime FLOAT NOT NULL,
    time BIGINT NOT NULL,
    received_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

Last updated