Unity API Reference
Namespace
using GameRebellionSdk.Unity;
GameRebellion (Static Class)
Lifecycle
| Method | Returns | Description |
|---|---|---|
Initialize(string apiKey) | bool | Initialize the SDK. Call once in Awake(). |
Shutdown(string endReason = "normal") | void | Flush pending events and shut down. |
GetState() | SdkState | Current SDK state. |
GetLastError() | string | Last error message from the native core. |
SDK State
| Value | Meaning |
|---|---|
SdkState.Uninitialized | Not yet initialized |
SdkState.Initializing | Init in progress |
SdkState.Ready | Accepting events |
SdkState.Paused | Paused (events cached) |
SdkState.Flushing | Sending a batch |
SdkState.ShuttingDown | Shutdown in progress |
SdkState.Error | Unrecoverable error |
Controls
| Method | Description |
|---|---|
SetConsent(Consent consent) | Set user consent (Unknown, Granted, Denied). Controls PII collection. |
SetPaused(bool paused) | Pause/resume event processing. While paused, a session_stop is cached. |
SetNetworkOnline(bool online) | Force the SDK online or offline. |
Flush() | Immediately send all buffered events. |
Event Tracking
| Method | Required Fields | Dashboard |
|---|---|---|
TrackEvent(string name, string json) | — | Depends on event name |
TrackFeatureUse(GrFeatureUseEvent) | Type | Engagement |
TrackProgression(GrProgressionEvent) | Type, Status | Progression |
TrackLevelUp(GrLevelUpEvent) | — | Progression |
TrackAchievement(GrAchievementEvent) | Id | Progression |
TrackTransaction(GrTransactionEvent) | Currency | Monetization |
TrackCryptoTransaction(GrCryptoTransactionEvent) | Amount, Currency | Monetization |
TrackAdView(GrAdViewEvent) | — | Monetization |
TrackAdClick(GrAdClickEvent) | — | Monetization |
TrackAdError(GrAdErrorEvent) | — | Technical |
TrackAdReward(GrAdRewardEvent) | — | Monetization |
TrackLog(GrLogEvent) | Type | Technical |
TrackLevelCompleted(int level, int score, string difficulty, string email) | — | Progression |
TrackFriendInvite(GrFriendInviteEvent) | — | Social |
TrackGroupJoin(GrGroupJoinEvent) | — | Social |
TrackChatMessage(GrChatMessageEvent) | — | Social |
TrackVoiceCallStart(GrVoiceCallStartEvent) | Type | Social |
TrackVoiceCallStop(GrVoiceCallStopEvent) | — | Social |
Metrics
| Method | Description |
|---|---|
RecordFrame(double fps) | Record a frame's FPS value. Called automatically by GRMetricsCollector. |
RecordMemory(double memoryMB) | Record memory usage. Called automatically by GRMetricsCollector. |
DrainAndLogSDKLogs() | Print buffered native SDK logs to Unity Console. |
GRMetricsCollector (MonoBehaviour)
Auto-created as a hidden, persistent (DontDestroyOnLoad) GameObject on successful initialization. Tracks FPS and memory, and manages app lifecycle.
| Field | Default | Description |
|---|---|---|
trackFPS | true | Enable FPS tracking |
trackMemory | true | Enable memory tracking |
memorySampleInterval | 0.5f | Seconds between memory samples |
logMetrics | false | Print metrics to console |
logInterval | 5f | Seconds between console logs (when enabled) |
GRLogDrainer (MonoBehaviour)
Periodically drains native SDK logs into the Unity Console with [GRC] prefix.
| Field | Default | Description |
|---|---|---|
drainInterval | 1.0f | Seconds between drain calls |
enableLogDraining | true | Enable/disable log draining |
Error Codes
| Code | Constant | Meaning |
|---|---|---|
0 | GR_OK | Success |
-1 | GR_ERR_GENERIC | Native exception, missing plugin, or Editor stub |
-2 | GR_ERR_INVALID_ARGS | Missing required fields |
-3 | GR_ERR_INVALID_STATE | SDK not initialized or not in Ready state |