Overview
This page provides a comprehensive example of integrating the KeewanoSDK APIs into a Unity sample game, giving developers a clear, step-by-step reference for a flawless implementation.
Key Concept: Context-First Events
Traditional analytics repeat lots of properties on every event (level, device, A/B group, campaign, …).
Keewano DB keeps a single, ordered event stream per user.
Once context enters the stream, the system automatically reuses it as context for every subsequent event - so you DO NOT need to re-send the info, but only send state changes.
For example:
Scenario | Legacy payload | Keewano call |
Level 15 won | {event:"level_win", level:15, difficulty:"medium", segment:"A/B_1", device:"iPhone13"} | KeewanoSDK.ReportLevelWin(15); |
Banner store opened | {event:"store_open", placement:"main_banner", utm_campaign:"SpringSale"} | KeewanoSDK.ReportWindowOpen("Store_MainBanner"); |
FTUE milestone step 3 | {event:"tutorial_step", step:3, ab_group:"tutorial_redesign"} | KeewanoSDK.ReportOnboardingMilestone("Step 3"); |
Game Name
Space Shooter
Game Description
Space Shooter is a top-down shooter in which the player pilots a spaceship through ten levels to save the galaxy.
- Goal: Defeat enemy waves before time runs out, collect data cores to upgrade your ship and beat the final boss.
- Progression: Clear levels to unlock ship skins, weapons, and power-ups.
- Currencies & Rewards:
- Crystals (premium currency acquired via IAP)
- Metal Shards (crafting material earned by defeating enemies)
- Data Cores (warp-gate charge modules dropped by elite foes or hidden in secret crates)
- Fuel Cells (consumable energy for your ship’s special abilities, refills at UTC midnight)
- Ship Skins (cosmetic items unlocked by level completion or purchased with Crystals)
- Weapons (standard and special armaments unlocked through progression or crafted with Metal Shards)
- Power-Ups (temporary in-combat boosts earned in levels or bought in the store)
- Menus & Windows:
- Main Menu (The landing screen when the game launches. Options: Play, Tutorial, Settings, Store, Inventory, and Leaderboard)
- Pause Menu (Accessible during gameplay. Options: Resume, Restart, Quit)
- Galactic Store (In-game shop where players spend Crystals or Metal Shards to buy ship skins, weapon upgrades, and limited-time bundles)
- Inventory (Displays all owned ship skins, weapons, power-ups, and Consumables [Fuel Cells, Data Cores]. Allows equip/upgrade actions)
- Leaderboard (Shows top player rankings for time-trial scores, fastest level clears, and highest overall campaign progress)
- Win/Lose:
- Win: Boss Health → 0
- Lose: Ship Health → 0 or time runs out
Integration Scenarios
Scenario 1: First Launch & Consent
Player Action: Installs the game and opens it for the first time.
Developer: Split responsibilities into clear initialization stages:
- Consider the User Consent setting.
- Attention
- This is relevant if your project or regional requirements demand explicit player consent before any analytics data is sent.
See Data Privacy for more details about User Consent.
If Player consent is required in your game, set it in the following way: bool consent = ShowConsentDialog();
Definition KeewanoSDK.cs:18
static void SetUserConsent(bool consentGiven)
Sets the user's consent for data collection and analytics.
Definition KeewanoSDK.cs:199
- Note
- If consent was denied, no analytics data will ever be sent.
- Consider marking devices as testers for QA purposes:
void ConfigureTestUser()
{
}
static void MarkAsTestUser(string testerName)
Marks the device as a test user.
Definition KeewanoSDK.cs:430
- Note
- We recommend using this feature to isolate test data.
- Retrieve anonymous install ID for later attribution or debugging:
static Guid GetInstallId()
Retrieves the unique installation ID for the game.
Definition KeewanoSDK.cs:217
- Consider campaign attribution:
void OnCampaignDetected(string campaignSource)
{
if (!string.IsNullOrEmpty(campaignSource))
}
static void ReportInstallCampaign(string campaignName)
Reports a marketing install campaign for this user.
Definition KeewanoSDK.cs:276
Scenario 2: Player Registration & Sign-In
Player Action: Opens the Sign Up form, fills details (email/password), taps Register.
Developer: After your auth service returns a new playerId:
void OnRegistrationSuccess(Guid playerId)
{
}
static void SetUserId(UInt64 uid)
Sets the user identifier using a UInt64 value.
Definition KeewanoSDK.cs:367
- Note
- PlayerId can be a Guid or UInt64 value, according to your game needs.
void AssignToAbGroup(char abGroup)
{
}
static void ReportABTestGroupAssignment(string testName, char group)
Marks the user as a participant in an specific test group.
Definition KeewanoSDK.cs:317
Scenario 3: Entering Main Menu & Changing Language
Player Action: After login, the Main Menu pops up. The player opens Settings and switches the language to French. Then closes Settings.
Developer: In your MainMenuHandler:
void OnMainMenuOpened()
{
}
void OnMainMenuClosed()
{
}
void OnSettingsOpened()
{
}
void OnSettingsClosed()
{
}
static void ReportWindowClose(string windowName)
Reports a window/popup close event.
Definition KeewanoSDK.cs:253
static void ReportWindowOpen(string windowName)
Reports a window/popup open event.
Definition KeewanoSDK.cs:242
- Attention
- You do NOT have to call KeewanoSDK.ReportWindowOpen/ KeewanoSDK.ReportWindowClose manually if you add the 'KeewanoWindow' component to your UI GameObject.
It will automatically track window open/close events.
See the Windows and Popups section for more details.
void OnLanguageChanged(string newLangCode)
{
}
static void ReportGameLanguage(string language)
Reports the game language.
Definition KeewanoSDK.cs:288
Scenario 4: FTUE Milestones Tracking
Player Action: During the first session the player completes key milestones.
Developer: Hook into your milestones points:
void OnEnemyKill()
{
if (KilledFirstBoss)
}
void OnRewardCollection()
{
if (CollectedFirstReward)
}
void OnLevelStart(uint levelNumber)
{
}
void OnLevelWin(uint levelNumber)
{
}
void OnIAP()
{
if (FirstIAP)
}
void OnTutorialStart()
{
}
void OnTutorialQuitMidway()
{
}
void OnTutorialComplete()
{
}
static void ReportOnboardingMilestone(string milestoneName)
Report that a user has reached a milestone during the onboarding (game tutorial) process.
Definition KeewanoSDK.cs:302
- Note
- Important: Do NOT use custom events to report onboarding milestones.
Using KeewanoSDK.ReportOnboardingMilestone API fuels the Keewano AI's FTUE funnel so it can flag tutorial drop-offs automatically.
Scenario 5: Level Start & Completion
Player Action: From Main Menu the player taps Play, chooses Level 1, fights through 5 waves and win/lose the level
Developer:
- Attention
- In this scenario you need to use custom events, see Custom Events for more details regarding custom events generation.
In your LevelManager:
void OnLevelStart(uint levelNumber)
{
}
void OnLevelEnd(uint levelNumber)
{
}
void OnLevelWin(uint levelNumber)
{
}
void OnLevelLose(uint levelNumber)
{
}
- Note
- Always pass the exact same IDs (i.e. levelNumber value) to these calls so that progression analytics remain accurate and consistent. This will allow the Keewano AI agents build and explore an informative progression report.
- Always pass raw values directly to the SDK APIs, never as formatted strings:
✅ KeewanoSDK.ReportLevelStart(15) - pass numbers directly
⛔ KeewanoSDK.ReportLevelStart("15") - don't pass numbers as strings
✅ KeewanoSDK.ReportEnemyKilled("Orc") - strings should be actual strings
⛔ KeewanoSDK.ReportEnemyKilled("enemy_type=Orc") - avoid formatted labels
- Avoid wrapping values in labels or descriptive text:
✅ KeewanoSDK.ReportLevelWin(10)
⛔ KeewanoSDK.ReportLevelWin("level = 10")
✅ KeewanoSDK.ReportEnterMainLevel(3)
⛔ KeewanoSDK.ReportEnterMainLevel("stage_3")
Scenario 6: In-Game Combat & Power-Ups
Player Action: Destroys regular enemies, then uses the “Hyper Beam” power-up before fighting strong “Omega Crusher” enemy.
Developer: In your CombatController:
void OnEnemyDestroyed(string enemyType)
{
}
void OnPowerUpUsed(string powerName)
{
}
static void ReportItemsExchange(string exchangeLocation, Item[] from, Item[] to)
Reports an item exchange event using item arrays.
Definition KeewanoSDK.cs:333
Represents a game item with a unique identifier and a quantity.
Definition KeewanoItems.cs:8
- Note
- Always Prefer using KeewanoSDK.ReportItemsExchange and KeewanoSDK.ReportItemsReset instead (or in addition to) a decidacted custom event.
It will help Keewano AI to track the game balance.
Scenario 7: Store Purchases (IAP)
Player Action: Opens Galactic Store, buys 500 crystals for $4.99.
Developer: After successful IAP callback:
void OnGalacticStoreOpen()
{
}
void OnIAPSuccess(string product, uint priceInUsdCents)
{
}
void OnGalacticStoreClose()
{
}
static void ReportInAppPurchase(string productName, uint priceUsdCents)
Reports an in-app purchase event.
Definition KeewanoSDK.cs:265
Scenario 8: Daily Resets
Auto Action: At UTC midnight, Daily Fuel resets to 100.
Developer: In your DailyResetService:
void OnDailyReset()
{
}
static void ReportItemsReset(string location, Item[] items)
Resets the user's items at a specified location.
Definition KeewanoSDK.cs:406
Scenario 9: Non Unity.UI Buttons & Window Flow
Player Action: Within Main Menu, taps Leaderboard button (which is implemented outside of Unity.UI), scans top scores, then closes it.
Developer: In your UIController:
void OnLeaderboardWindowOpen()
{
}
void OnLeaderboardButtonClicked()
{
OpenLeaderboard();
}
void OnLeaderboardWindowClose()
{
}
static void ReportButtonClick(string buttonName)
Reports a button click event.
Definition KeewanoSDK.cs:231
- Note
- KeewanoSDK automatically collects button click events when using Unity.UI system. If your game uses a custom UI subsystem but not implemented as standard Unity.UI, use ReportButtonClick method
Scenario 10: Advanced Item & Goal Tracking
Player Action: The player starts Level 5 Nebula Siege, where he must collect 2 Data Cores and 1 Metal Shard to power the warp gate.
Developer: In your LevelManager relevant functions integrate this flow:
Scenario 11: Custom Error Reporting
Player Action: A non-fatal issue occurs or domain-specific validation triggered.
Developer:
- Attention
- Keewano AI automatically gathers unhandled exceptions and Unity error log messages. Use the following method to log any additional handled exceptions or custom errors that may not be captured by the system.
In your errors handler:
void ErrHandler(string err)
{
}
static void LogError(string message)
Reports a technical issue encountered during gameplay.
Definition KeewanoSDK.cs:442