SDK Features
Debugging
The SDK is designed to be as silent as possible and use very few resources. You will therefore not get much information by default in your development console.
We have 2 different debug log types that can be enabled / disabled (at any time).
- info log
- verbose log
Info log
Short messages will be output when enabled explaining when some action is being performed by the SDK. Sometimes cropping text / values to make it more readable.
Enable info log when implementing the SDK – remember to turn it off in production!
GameAnalytics.SetEnabledInfoLog(true);
Info/GameAnalytics: Add DESIGN event: {eventId:someEvent, value:0}
Info/GameAnalytics: Add DESIGN event: {eventId:someOtherEvent, value:100}
Info/GameAnalytics: Add ERROR event: {severity:info, message:This is some in}
Verbose Log
Console output when each event is added (all fields) in JSON string format. This is the data being submitted to the GA servers for each event.
Enable verbose log when troubleshooting events.
GameAnalytics.SetEnabledVerboseLog(true);
This can result in a lot of text. When troubleshooting/debugging events it is therefore recommended to enable/disable when performing the action that needs inspection.
Troubleshooting example:
// enable verbose log
GameAnalytics.SetEnabledVerboseLog(true);
// add event you need to troubleshoot / inspect
GameAnalytics.AddDesignEvent("Some:Event", 100);
// disable verbose log
GameAnalytics.SetEnabledVerboseLog(false);
Verify Implementation
Enable the Info Log to verify that events are being sent from your game project without any issues being reported.
Events submitted should register after a minor delay in our realtime dashboard in the GameAnalytics tool.
Read more about the realtime dashboard and our data processing.
Session Handling
Sessions are the concept of a user spending focused time in your game – from game launch to the user leaving the game.
On UWP and Universal Windows 8 a new session will start once the game is launched (or when the app is “resuming”). A session will end once the game is suspended. To manually handle the start and end of session, enable manual session handling by calling GameAnalytics.SetEnabledManualSessionHandling(true) and then use GameAnalytics.EndSession() and GameAnalytics.EndSession().
On Mono / .Net 4.5 GameAnalytics.EndSession() should be called manually before quitting the game to create an end session event. If a new session needs to be started during the game’s lifetime it can done by calling GameAnalytics.EndSession(). NB there no check for manual session handling on Mono / .Net 4.5.
Session start
Generate new session. Adds a session start event (a user
event). Starts the periodic activation of submitting queued events.
Next event submit will fix potential missing session_end from earlier sessions.
Session end
Stops the periodic activation of submitting queued events. Adds a session_end
event and submits queued events.
Event Queue
Whenever an event is added (and validated) it will be added to a local database queue.
Interval
Every 8 seconds the SDK will start a task for submitting queued events since last submit. This processing is done in a separate low-priority thread that will have minimum impact on performance. The payload is gzipped and will therefore only consume a small amount of bandwidth. Offline
When a device is offline the events are still added to the queue. When the device is online it will submit.
Thread Handling
Almost every piece of this code is run using a dedicated low-priority serial thread queue to avoid UI lag or sudden performance spikes.
The queue will execute each task sequentially. If the SDK adds several tasks to the queue then each will be executed in turn. A task could be adding an event or submitting all queued events.
Consider this example with 3 calls.
// Configure build version
GameAnalytics.ConfigureBuild("alpha 0.1.0");
// Initialize
GameAnalytics.Initialize("12341234123412341234123412341234", "1234123412341234123412341234123412341234");
// Add Design event
GameAnalytics.AddDesignEvent("Some:Event");
The configureBuild
is required to be called before initialize is completely finished. The design event call is required after initialize is finished. The queuing will make sure that each task is completely finished before proceeding to the next one.
Custom Dimensions
GameAnalytics support the use of up to 3 custom dimensions.
- Custom01
- Custom02
- Custom03
During the game it is possible to set the active value for each custom dimension dynamically. Once a dimension is set it will be persisted across sessions/game-start and automatically be added to all event categories. Remember you have to set the custom dimensions before initialzing the SDK (but after setting the available custom dimensions) to be able to add the dimensions to the first session start event.
Setting each custom dimension. To reset a set custom dimension simply just set it to empty string or null.
GameAnalytics.SetCustomDimension01("ninja");
GameAnalytics.SetCustomDimension02("dolphin");
GameAnalytics.SetCustomDimension03("horde");
GameAnalytics.SetCustomDimension03(""); // reset custom dimension 3
|Field|Type|Description|Example| |customDimension|string|One of the available dimension values set in the configuration phase. Will persist cross session. Set to empty string or null to reset.|ninja|
Read more about custom dimensions here
Custom Event Fields
Custom event fields will not be available in the GameAnalytics web-tool.
For more information on custom event fields and raw data export go here.
Custom event fields are a collection of key-value pairs that can be added to any event during gameplay. These global custom event fields can be updated at any time.
You can also override the global custom event fields by using the optional custom event fields parameter when sending individual events. For more information on how to use this feature, please refer to the events documentation page.
To set global custom event fields, follow these steps:
Dictionary<string, object> customFields = new Dictionary<string, object>();
customFields.Add("test", 1000);
customFields.Add("test_2", "global_hello_world");
GameAnalytics.SetGlobalCustomEventFields(customFields);
Field | Type | Description | Example |
---|---|---|---|
customFields | dictionary | A set of key-value pairs. Values can be strings or numbers | { "test": 1000 "tests": "hello_world" } |