Skip to main content

Unity API Reference

Namespace

using GameRebellionSdk.Unity;

GameRebellion (Static Class)

Lifecycle

MethodReturnsDescription
Initialize(string apiKey)boolInitialize the SDK. Call once in Awake().
Shutdown(string endReason = "normal")voidFlush pending events and shut down.
GetState()SdkStateCurrent SDK state.
GetLastError()stringLast error message from the native core.

SDK State

ValueMeaning
SdkState.UninitializedNot yet initialized
SdkState.InitializingInit in progress
SdkState.ReadyAccepting events
SdkState.PausedPaused (events cached)
SdkState.FlushingSending a batch
SdkState.ShuttingDownShutdown in progress
SdkState.ErrorUnrecoverable error

Controls

MethodDescription
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

MethodRequired FieldsDashboard
TrackEvent(string name, string json)Depends on event name
TrackFeatureUse(GrFeatureUseEvent)TypeEngagement
TrackProgression(GrProgressionEvent)Type, StatusProgression
TrackLevelUp(GrLevelUpEvent)Progression
TrackAchievement(GrAchievementEvent)IdProgression
TrackTransaction(GrTransactionEvent)CurrencyMonetization
TrackCryptoTransaction(GrCryptoTransactionEvent)Amount, CurrencyMonetization
TrackAdView(GrAdViewEvent)Monetization
TrackAdClick(GrAdClickEvent)Monetization
TrackAdError(GrAdErrorEvent)Technical
TrackAdReward(GrAdRewardEvent)Monetization
TrackLog(GrLogEvent)TypeTechnical
TrackLevelCompleted(int level, int score, string difficulty, string email)Progression
TrackFriendInvite(GrFriendInviteEvent)Social
TrackGroupJoin(GrGroupJoinEvent)Social
TrackChatMessage(GrChatMessageEvent)Social
TrackVoiceCallStart(GrVoiceCallStartEvent)TypeSocial
TrackVoiceCallStop(GrVoiceCallStopEvent)Social

Metrics

MethodDescription
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.

FieldDefaultDescription
trackFPStrueEnable FPS tracking
trackMemorytrueEnable memory tracking
memorySampleInterval0.5fSeconds between memory samples
logMetricsfalsePrint metrics to console
logInterval5fSeconds between console logs (when enabled)

GRLogDrainer (MonoBehaviour)

Periodically drains native SDK logs into the Unity Console with [GRC] prefix.

FieldDefaultDescription
drainInterval1.0fSeconds between drain calls
enableLogDrainingtrueEnable/disable log draining

Error Codes

CodeConstantMeaning
0GR_OKSuccess
-1GR_ERR_GENERICNative exception, missing plugin, or Editor stub
-2GR_ERR_INVALID_ARGSMissing required fields
-3GR_ERR_INVALID_STATESDK not initialized or not in Ready state