gamemantra.aigamemantra.ai|Developer Docs

Developer Documentation · Integration Package

Zero-Friction Integration

Download a ready-to-use package from the dashboard — binaries, scripts, and a pre-filled config are bundled together. Extract the ZIP at your Unity project root (so its Assets/ merges into yours) and press Play. No key copy-paste. No manual configuration.

📦

One Download

Full ZIP containing SDK binaries, C# scripts, and gamemantra_config.json — pre-filled with your API key and game ID.

🔑

Keys Pre-Filled

api_key and game_id are injected at download time. You never copy, paste, or type them into your project.

Auto-Bootstrap

GameMantraAutoInit.cs fires via [RuntimeInitializeOnLoadMethod]. The SDK initialises before your first scene loads.

1

Choose Your Environment

The environment is baked into gamemantra_config.json at download time — the SDK uses the correct API endpoint automatically. No code change is needed when moving from sandbox to production: just re-download the package.

API endpointhttps://sandbox.gamemantra.aiTLS not verified
2

Download the Package

Go to Dashboard → Games, open your game's detail drawer, select the environment above, then click Download Package. The ZIP contains everything — no separate binary download needed.

gamemantra_unity_YourGame_sandbox.zip

Assets/
├── Resources/
├── gamemantra_config.json← pre-filled: api_key + game_id + base_url
├── Scripts/
├── GameMantraAutoInit.cs← auto-bootstrap (no manual wiring)
├── GameMantraSDK.cs
├── GameMantraConfig.cs
├── Plugins/Android/
├── libFlutterUnityPlugin.so← ARM64 binary
├── libflutter_engine.so
├── StreamingAssets/flutter_data/
├── icudtl.dat
├── libapp.so← Experience AOT snapshot
├── flutter_assets/
3

What's inside gamemantra_config.json

This file is generated fresh for your game at every download. You never edit it — just use it. Showing config for 🧪 sandbox environment.

Assets/Resources/gamemantra_config.json
{
  "api_key": "gm_test_sk_YOUR_SANDBOX_KEY",
  "game_id": "33333333-3333-4333-8333-333333333333",
  "environment": "sandbox",
  "base_url": "https://sandbox.gamemantra.ai",
  "auto_login": true,
  "player_id_source": "device",
  "flutter_data_folder": "flutter_data",
  "flutter_engine_so": "libflutter_engine.so",
  "pixel_ratio": 1,
  "bootstrap_version": "1.0.0",
  "debug_logging": true
}
api_key

Injected at download time — never copy-pasted

game_id

Your game UUID from the wizard — injected automatically

environment

"sandbox" — drives TLS verification and key format

base_url

https://sandbox.gamemantra.ai

pixel_ratio

Always 1.0 — never auto-detect from device DPI (§14)

debug_logging

true in sandbox — verbose logcat output

4

Auto-Bootstrap Code

The bootstrap script is included in the package and runs automatically — no scene setup, no MonoBehaviour drag-and-drop required.

Assets/Scripts/Flutter/GameMantraAutoInit.cs
using UnityEngine;
using Gamemantra;

// GameMantraAutoInit.cs — included in every download package.
// [RuntimeInitializeOnLoadMethod] fires automatically when the game starts.
// No manual scene setup, no drag-and-drop, no key copy-paste.

public static class GameMantraAutoInit
{
    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
    private static void Bootstrap()
    {
        // 1. Load gamemantra_config.json from Resources/ (pre-filled at download time)
        var config = GameMantraConfig.Load(); // → Resources/gamemantra_config.json

        // 2. Initialise SDK (api_key + game_id already in config, never typed manually)
        var result = GameMantraSDK.Init(config);
        if (result != GMResult.OK)
        {
            Debug.LogError($"[GameMantra] Init failed: {result}");
            return;
        }

        // 3. Register player (device ID used when player_id_source = "device")
        GameMantraSDK.LoginPlayer(SystemInfo.deviceUniqueIdentifier);

        Debug.Log("[GameMantra] SDK ready — offer pipeline active.");
    }
}
5

Verify on Device

Run the game on an Android device and check logcat for this boot sequence. The correct base_url confirms the selected environment was picked up correctly.

adb logcat -s GameMantra:V
GM_Init: env=sandbox base_url=https://sandbox.gamemantra.ai
GM_Init: result=0 ← 0 = GM_OK
GMApiClient: GET https://sandbox.gamemantra.ai/v1/sdk/status/... → http=200
setDartFunctionPtr: 'GM_Dart_OnSDKReady' registered
setDartFunctionPtr: 'GM_Dart_OnOfferReceived' registered
setDartFunctionPtr: 'GM_Dart_OnNoOffer' registered
[CB] present #1 *** FIRST FRAME *** — render pipeline active

HTTP Status Reference

http=200Success — SDK initialised, kill switch = NONE
http=0Transport error — no network OR libcurl stub active
http=401Invalid API key — check which key type matches the environment
http=403game_id in URL doesn't match the API key's registered game_id
6

Player Identification

The SDK supports four player_id_source values in gamemantra_config.json — pick the one that matches your auth model. The canonical field-by-field reference (matching the comments in GameMantraConfig.cs) lives on Player identity.

DEFAULTAuto — Device UUIDZero config needed

Unity: uses SystemInfo.deviceUniqueIdentifier — zero-friction, no user accounts. Experience overlay: optional loginPlayer() with no args generates an in-process UUID v4. Default player_id_source: "device" in your downloaded config.

⚠️ Device ID resets on wipe / reinstall. For a fourth option, see advertising_id (ATT on iOS).

RECOMMENDEDGame User IDFor games with user accounts

Pass your auth system's user ID after the player logs in. Set "player_id_source": "custom" and "auto_login": false in the config, then call the helper from your auth callback.

Assets/Scripts/Flutter/YourAuthController.cs
// Unity — call from your auth system's success callback

// Firebase Auth:
FirebaseAuth.DefaultInstance.StateChanged += (s, e) => {
    var user = e.auth.CurrentUser;
    if (user != null)
        GameMantraSDKHelper.SetGameUserId(user.UserId);
};

// Google Play Games Services:
PlayGamesPlatform.Instance.Authenticate(success => {
    if (success)
        GameMantraSDKHelper.SetGameUserId(
            PlayGamesPlatform.Instance.GetUserId());
});

// Steam:
if (SteamManager.Initialized)
    GameMantraSDKHelper.SetGameUserId(
        SteamUser.GetSteamID().ToString());

// Any custom auth system:
GameMantraSDKHelper.SetGameUserId(myAuth.CurrentUser.Id);
ADVANCEDJWT Claim ExtractionFor token-based auth

SDK decodes your auth JWT (Base64URL, no signature verification — the server verifies signatures). Extracts the named claim as the player identifier. Set "player_id_source": "jwt".

Assets/Scripts/Flutter/YourAuthController.cs
// Unity — pass the raw JWT from your backend

// Firebase ID token → extracts "user_id" claim:
string token = await firebaseUser.GetIdTokenAsync();
GameMantraSDKHelper.SetPlayerFromJwt(token, "user_id");

// Generic JWT → extracts "sub" by default:
GameMantraSDKHelper.SetPlayerFromJwt(token);

// Custom backend JWT with a different claim:
GameMantraSDKHelper.SetPlayerFromJwt(token, "player_id");

Common JWT claim names by platform:

Firebase Auth"user_id" or "sub"
Google Sign-In"sub"
Apple Sign-In"sub"
PlayFab"PlayFabId" (custom)
Auth0"sub"
Custom backendany claim you define

Config for each strategy

Assets/Resources/gamemantra_config.json (relevant fields)
// Strategy 1 — Auto (default, no changes needed)
{
  "player_id_source": "device",
  "auto_login": true
}

// Strategy 2 — Game user ID (set in config, call SetGameUserId() in code)
{
  "player_id_source": "custom",
  "auto_login": false
}

// Strategy 3 — JWT claim (set in config, call SetPlayerFromJwt() in code)
{
  "player_id_source": "jwt",
  "jwt_player_id_claim": "sub",
  "auto_login": false
}

AI Integration Prompt

Copy this prompt into any AI coding assistant (Cursor, Copilot, Claude, ChatGPT) to get a step-by-step integration guide tailored to your specific auth system.

AI Prompt — Copy & Paste
I'm integrating the GameMantra AI monetization SDK into my Unity game.

My game setup:
- Engine: Unity (C#)
- Auth system: [Firebase / Google Play Games / Steam / Custom backend / No auth]
- Player ID available: [e.g. Firebase user.uid / Steam SteamID / none — use device ID]
- Target platform: Android

I have already:
1. Downloaded the GameMantra integration package from the dashboard
2. Placed the .so files in the correct folders
3. Added gamemantra_config.json to Resources/

Now I need help with:
1. Connecting my auth system's player ID to GameMantra's LoginPlayer call
2. The exact code to call after my auth callback fires (show me a complete example)
3. How to verify on device that the player session was registered (logcat lines to look for)
4. When to call getNextOffer() to trigger the first AI offer (based on game events)

Please provide copy-paste ready code for my auth system.

Fill in the bracketed fields with your specific setup before sending to the AI assistant.

Critical Rules

  • Never set pixel_ratio from device DPI — always 1.0.
  • Never call runApp() before initFlutterUnreal().
  • Never commit a production package (with gm_live_sk_*) to a public repository.
  • Re-download when switching sandbox → production — do not hand-edit gamemantra_config.json.