# How to add analytics to a GameMaker game

> Send GameMaker events with http_request and the Async HTTP event: a saved player ID, a buffer file queue with retries, consent and HTML5 notes.

By Yos Riady. Updated 2026-11-18. Published 2026-11-18. Canonical URL: https://manalens.dev/blog/gamemaker-analytics

Call http_request() with a DS map of headers and a JSON body to post events to /v0/events, up to 50 per request. The GameMaker manual says the reply arrives in the Async HTTP event, in the async_load map. Keep the player ID in an INI file, the queue in a buffer file, and send nothing before consent.

## Key points

- GameMaker posts analytics events with http_request() to /v0/events, with 1 to 50 events per request and the reply in the Async HTTP event.
- Call randomise() before you build the anonymous ID, because without it every GameMaker install gets the same UUID.
- Call date_set_timezone(timezone_utc) before you build timestamps, or a local time with a Z suffix can get the whole batch refused with 400.

## Which route fits a GameMaker game?

HTTP from GML. GameMaker has no Manalens extension, and its own analytics options sit in the HTML5 game options, where the manual marks analytics_event as deprecated. http_request(url, method, header_map, body) works on every export and returns a request ID.

Put the code in one persistent object, obj_analytics, in your first room. It keeps the ID, the session, the queue and the request in flight, and it answers the Async HTTP event for its own request.

Sources: GameMaker manual, http_request, Async HTTP event and analytics_event; Manalens app events documentation.

## What must every GameMaker event contain?

One JSON envelope, the same one the Godot and Unity SDKs send. POST it to /v0/events on your collector with two headers: x-publishable-key and Content-Type: application/json. The body is {"events": [...]} with 1 to 50 events. A good request returns {"accepted":N}.

- type "track", an event name in snake_case, channel "app" and version (your tracker version, up to 32 characters).
- message_id: a new UUID version 4 for each event. Keep it on a retry. The collector counts each message_id once.
- anonymous_id: one UUID version 4 per install, saved on the device. The collector checks the version digit, so a random hex string of the same length is refused.
- session_id: 1 to 64 characters of letters, digits and . _ : -. Start a new one after 30 minutes without play.
- original_timestamp: the time of the event in ISO 8601 UTC, such as 2026-11-09T10:00:00Z. It can be up to 7 days old, and at most 10 minutes in the future.
- context.app.platform (windows, macos, linux, web, android, ios or other) and engine "other". Add storefront, app_version and build to filter reports by build.
- properties: a flat object of strings, numbers, booleans or null.

Sources: Manalens app events documentation.

## How do I send events from GameMaker?

Add the Create event code below. randomise() seeds the random generator, so each install gets its own UUID. date_set_timezone(timezone_utc) makes the date_get_* functions return UTC parts, so the timestamp is correct. GameMaker has no ISO 8601 formatter, so iso_now() builds the string.

The ID and the consent flag go in manalens.ini. The queue goes in mana_queue.dat as a JSON string inside a buffer. A timer from call_later() flushes every 30 seconds.

``` GML (Create event)
// obj_analytics, Create event (mark the object Persistent)
#macro MANALENS_URL "https://YOUR_COLLECTOR_ENDPOINT/v0/events"
#macro MANALENS_KEY "YOUR_PUBLISHABLE_KEY"
randomise();
date_set_timezone(timezone_utc);
headers = ds_map_create();
headers[? "Content-Type"] = "application/json";
headers[? "x-publishable-key"] = MANALENS_KEY;
queue = []; inflight = -1; inflight_n = 0; backoff = 2;
anon_id = ""; session_id = ""; consent = false; session_start_ms = current_time;

uuid4 = function() {
    var hex = "0123456789abcdef", s = "";
    for (var i = 1; i <= 36; i++) {
        if (i == 9 || i == 14 || i == 19 || i == 24) s += "-";
        else if (i == 15) s += "4";
        else if (i == 20) s += string_char_at("89ab", irandom(3) + 1);
        else s += string_char_at(hex, irandom(15) + 1);
    }
    return s;
};
pad = function(n) { return string_replace_all(string_format(n, 2, 0), " ", "0"); };
iso_now = function() {
    var d = date_current_datetime();
    return string(date_get_year(d)) + "-" + pad(date_get_month(d)) + "-" + pad(date_get_day(d)) + "T"
        + pad(date_get_hour(d)) + ":" + pad(date_get_minute(d)) + ":" + pad(floor(date_get_second(d))) + ".000Z";
};
save_queue = function() {
    var b = buffer_create(1024, buffer_grow, 1);
    buffer_write(b, buffer_string, json_stringify(queue));
    buffer_save(b, "mana_queue.dat");
    buffer_delete(b);
};
load_queue = function() {
    var b = buffer_load("mana_queue.dat");
    if (b == -1) return [];
    var s = buffer_read(b, buffer_string);
    buffer_delete(b);
    try { return json_parse(s); } catch (e) { return []; }
};
track = function(name, props) {
    if (!consent) return;
    array_push(queue, { type: "track", event: name, channel: "app", version: "0.1.0",
        message_id: uuid4(), anonymous_id: anon_id, session_id: session_id, original_timestamp: iso_now(),
        context: { app: { platform: "windows", storefront: "steam", app_version: "1.4.0", build: "571", engine: "other" },
                   locale: "en", library_name: "my-game", library_version: "1.4.0" },
        properties: props });
    save_queue();
    if (array_length(queue) >= 50) flush();
};
flush = function() {
    if (!consent || inflight != -1 || array_length(queue) == 0) return;
    inflight_n = min(50, array_length(queue));
    var batch = [];
    for (var i = 0; i < inflight_n; i++) array_push(batch, queue[i]);
    inflight = http_request(MANALENS_URL, "POST", headers, json_stringify({ events: batch }));
};
set_consent = function(on) {
    consent = on;
    ini_open("manalens.ini");
    ini_write_string("manalens", "consent", on ? "1" : "0");
    if (!on) {
        ini_key_delete("manalens", "anon_id"); ini_key_delete("manalens", "first_open_at"); ini_close();
        queue = []; if (file_exists("mana_queue.dat")) file_delete("mana_queue.dat");
        return;
    }
    anon_id = ini_read_string("manalens", "anon_id", "");
    var first = (anon_id == "");
    if (first) { anon_id = uuid4(); ini_write_string("manalens", "anon_id", anon_id); ini_write_string("manalens", "first_open_at", iso_now()); }
    var first_at = ini_read_string("manalens", "first_open_at", "");
    ini_close();
    queue = load_queue(); session_id = uuid4(); session_start_ms = current_time;
    track("game_open", { is_first_open: first, first_open_at: first_at });
    track("session_start", {});
    flush();
};
ini_open("manalens.ini"); var c = ini_read_string("manalens", "consent", "0"); ini_close();
if (c == "1") set_consent(true);
call_later(30, time_source_units_seconds, flush, true);
```

Sources: GameMaker manual, http_request, randomise, date_set_timezone, json_stringify, json_parse, ini_open, buffer_save, buffer_load and call_later.

## How do I handle the reply in the Async HTTP event?

Add an Async, HTTP event to the same object. It runs for every HTTP request in the game, in every object that has the event, so compare async_load[? "id"] with your request ID first. status is 1 while data downloads, 0 when the request is complete and below 0 on an error. http_status holds the HTTP code when it is available, so check it with is_undefined().

Game End sends session_end on desktop. The manual says the Game End event is really only viable on Windows, Ubuntu and macOS, so mobile sessions end without it. Track gameplay with obj_analytics.track("level_complete", { level: 3, score: 1200 }).

``` GML (Async HTTP, Game End and Clean Up events)
// obj_analytics, Async - HTTP event
if (async_load[? "id"] != inflight) exit;
if (async_load[? "status"] == 1) exit; // still downloading
inflight = -1;
if (!consent) exit;
var code = async_load[? "http_status"];
if (is_undefined(code)) code = 0;
if (code >= 200 && code < 300) { array_delete(queue, 0, inflight_n); save_queue(); backoff = 2; flush(); }
else if (code == 0 || code >= 500 || code == 408 || code == 429) {
    call_later(backoff, time_source_units_seconds, flush); backoff = min(backoff * 2, 300); }
else { array_delete(queue, 0, inflight_n); save_queue(); } // refused data: drop the batch

// obj_analytics, Game End event
track("session_end", { duration_s: floor((current_time - session_start_ms) / 1000) });

// obj_analytics, Clean Up event
ds_map_destroy(headers);

// Consent screen button, Left Released event:
// obj_analytics.set_consent(true);
```

Sources: GameMaker manual, Async HTTP event, is_undefined, Other events (Game End) and array_delete.

## How do the player ID, the offline queue and consent work?

The anonymous_id is a UUID version 4 in manalens.ini, written once after consent. The queue is saved to mana_queue.dat on every track() call, because GameMaker can close on mobile without a Game End event. A player who plays offline sends the queue at the next flush or the next launch.

Keep the batch and wait longer before each retry after a network error or a 5xx, 408 or 429 response. Drop it after any other 4xx, because the collector refused the data and a retry gets the same answer. That also clears a batch that holds an event older than 7 days, which the collector refuses with 400.

Until consent is on, track() does nothing and nothing is written except the consent flag. set_consent(false) deletes the ID and the queue file. Whether your game needs consent is a decision for you and your legal advisers.

Files live in the GameMaker sandbox: %localappdata% plus the game name on Windows, usually ~/Library/Application Support plus the game name on macOS, and browser local storage on HTML5 and GX.games.

Sources: GameMaker manual, The File System, Ini Files and buffer_save; Manalens app events documentation.

## What changes for web, desktop and mobile builds?

Set platform in the context for each export, for example web on HTML5. The rest of the code is the same on every target.

- Windows, macOS and Ubuntu: a native build sends no Origin header, so the collector accepts it with the Publishable key alone.
- HTML5 and GX.games: the browser applies its cross domain rules. The x-publishable-key header causes a CORS preflight, which the collector answers for your project domain, its subdomains and Allowed origins. *.itch.zone is allowed by default. The manual warns that a blocked request can look like a blank result or a 404.
- HTML5 storage: the INI and buffer files go into browser local storage, which holds about 1 to 5 MB. Keep the queue short.
- HTML5 timeouts: the manual says the connection timeout is not implemented on web platforms.
- Android: turn on the INTERNET permission in the Android Game Options. For target API 28 and later, plain http:// calls are blocked, so use an https:// endpoint.

Sources: GameMaker manual, HTTP functions, Android Game Options and The File System; Manalens app events documentation.

## What are the GameMaker gotchas?

Each of these breaks the data without an error message.

- Without randomise(), GameMaker uses the same seed on every run, so every player gets the same anonymous ID and all your players count as one.
- The date_get_* functions return local time unless you call date_set_timezone(timezone_utc). A local time with a Z suffix can sit more than 10 minutes in the future, and the collector refuses the whole batch with 400.
- Only one INI file can be open at a time, and the data is written only at ini_close(). Open, read or write, and close in the same function.
- The Async HTTP event fires for every HTTP request in the game. Without the id check, your analytics object reacts to your leaderboard or update check requests.
- An Android release build with the INTERNET permission off fails without a clear error. Test a release build on a device, not only the Windows target.

Sources: GameMaker manual, irandom and randomise, date_current_datetime and date_set_timezone, Android Game Options, ini_open and Async HTTP event.

## How do I check that GameMaker events arrive?

Send one batch from a development build and read the response status. The Async HTTP event should show http_status 200 for your request ID.

1. Create a test project in Manalens and copy its Publishable key.
2. Run the Windows target from the IDE with the debugger, and set a breakpoint in the Async HTTP event.
3. Send game_open and session_start from the GameMaker build, then check that the response is {"accepted":2}.
4. Open the activity feed and check that platform, build and engine are set on the events.
5. Switch off the network, play for a minute, switch it on, and check that the queued events arrive once.
6. Replace the test key with the production Publishable key before you ship.

Sources: Manalens app events documentation.

## How do I start?

Manalens is the analytics and growth engine built for games. Add obj_analytics to your first room, ask for consent, and use the Game KPIs board to compare D1 retention and level fail rates between builds.

- [All installation options](https://manalens.dev/docs/install)

Sources: Manalens product documentation.

## Frequently asked questions

### Does GameMaker have built-in analytics?

Only for HTML5. The manual lists options for Flurry or Google Analytics in the HTML5 game options and marks analytics_event as deprecated. For desktop and mobile builds, send events with http_request() and a JSON body to /v0/events, and read the reply in the Async HTTP event.

### Why do all my GameMaker players have the same ID?

Because GameMaker uses the same random seed on every run until you call randomise(). Every install then builds the same UUID from irandom(). Call randomise() once in the Create event before you make the ID, and save the ID in an INI file so it stays the same.

### How do I read the HTTP status code in GameMaker?

In the Async HTTP event, read async_load[? "http_status"] after you check that async_load[? "id"] is your request ID. The key is present only when the request has finished or failed, so test it with is_undefined() and treat a missing code as a network error.

### Does the GameMaker code work on HTML5?

Yes. http_request() works on HTML5, and the browser sends a CORS preflight because of the x-publishable-key header. The collector answers it for your project domain and Allowed origins, and *.itch.zone is allowed by default. Set platform to web, and keep the queue short, because browser storage is small.

## Sources

- [GameMaker manual: http_request (read 18 November 2026)](https://manual.gamemaker.io/monthly/en/GameMaker_Language/GML_Reference/Asynchronous_Functions/HTTP/http_request.htm)
- [GameMaker manual: Async HTTP event (read 18 November 2026)](https://manual.gamemaker.io/monthly/en/The_Asset_Editors/Object_Properties/Async_Events/HTTP.htm)
- [GameMaker manual: HTTP functions (read 18 November 2026)](https://manual.gamemaker.io/monthly/en/GameMaker_Language/GML_Reference/Asynchronous_Functions/HTTP/HTTP.htm)
- [GameMaker manual: randomise (read 18 November 2026)](https://manual.gamemaker.io/monthly/en/GameMaker_Language/GML_Reference/Maths_And_Numbers/Number_Functions/randomise.htm)
- [GameMaker manual: date_set_timezone (read 18 November 2026)](https://manual.gamemaker.io/monthly/en/GameMaker_Language/GML_Reference/Maths_And_Numbers/Date_And_Time/date_set_timezone.htm)
- [GameMaker manual: Ini Files (read 18 November 2026)](https://manual.gamemaker.io/monthly/en/GameMaker_Language/GML_Reference/File_Handling/Ini_Files/Ini_Files.htm)
- [GameMaker manual: buffer_save (read 18 November 2026)](https://manual.gamemaker.io/monthly/en/GameMaker_Language/GML_Reference/Buffers/buffer_save.htm)
- [GameMaker manual: The File System (read 18 November 2026)](https://manual.gamemaker.io/monthly/en/Additional_Information/The_File_System.htm)
- [GameMaker manual: Other events (Game End) (read 18 November 2026)](https://manual.gamemaker.io/monthly/en/The_Asset_Editors/Object_Properties/Other_Events.htm)
- [GameMaker manual: Android Game Options (read 18 November 2026)](https://manual.gamemaker.io/monthly/en/Settings/Game_Options/Android.htm)

## Related guides

- [Game marketing measurement guide](https://manalens.dev/blog/game-marketing-measurement-guide)
- [Engine analytics compared: Unreal, Godot, GameMaker, Construct, Phaser](https://manalens.dev/blog/game-engine-analytics-compared)
- [How to add analytics to a Construct 3 game](https://manalens.dev/blog/construct-3-analytics)
- [What events to track first in your game](https://manalens.dev/blog/game-tracking-plan-first-events)
- [Track an itch.io game](https://manalens.dev/integrations/itch-io)
- [Where to find game crash logs, by engine](https://manalens.dev/blog/game-crash-logs-by-engine)
- [Player analytics guides](https://manalens.dev/blog/topic/player-analytics)
- [How to add analytics to a GDevelop game](https://manalens.dev/blog/gdevelop-analytics)
- [How to add analytics to a Phaser game](https://manalens.dev/blog/phaser-analytics)
- [How to move from GameAnalytics to Manalens](https://manalens.dev/blog/migrate-from-gameanalytics)
- [How to add analytics to a Ren'Py game](https://manalens.dev/blog/renpy-analytics)
