Configuration
GameAnalytics provides multiple features and options that need to be configured before initializing the SDK.
Set the build version
The build is used to specify the current version of your game. Specify it using a string. We recommend a 3 digit version like [major].[minor].[patch].
ga_configure_build("1.0.0");
User ID
In order to identify users and keep track of events, GameAnalytics will issue a unique user id automatically. It will be assigned the first time the SDK is initialized and will persist across sessions, no configuration required.
Set a custom user ID
While the default user id will suffice for most use cases, you can set a custom one before initializing the SDK:
ga_configure_user_id("my_user_id");
Set an optional External User ID
Besides the user id, GameAnalytics also supports an optional identifier called external user id, which is attached to every event alongside the regular user id.
Read more about the external user id here.
ga_configure_external_user_id("my_ext_uid");
Reading the ids back
var user_id = ga_get_user_id();
var ext_user_id = ga_get_external_user_id();
ga_get_user_id() and ga_get_external_user_id() only return a value on Windows, macOS and Linux. On Android, iOS and HTML5 they return an empty string.
Configure Privacy
You can manually turn off or on event submission. This is useful if you need, for GDPR purposes, to disable event submission.
ga_set_event_submission(false);
Event submission is enabled by default. Remote configs are still received even while event submission is disabled.
The optional second argument, cacheLocally, keeps events queued locally while submission is off, so they can be sent later once you enable it again:
ga_set_event_submission(false, true);
cacheLocally is honoured on Android, iOS and HTML5. On Windows, macOS and Linux it is ignored.
Resources
When submitting resource events you will be required to specify a resource currency and resource item type. You must register a whitelist for each before initializing the SDK. Submitting a resource event with a value outside these lists will result in the event being rejected by the SDK.
Currencies
ga_configure_resource_currencies(["gold", "gems"]);
The following limitations apply:
- You can have a maximum of 20 resource currencies.
- Each resource currency string can only contain letters (
[A-Za-z]).
Item Types
ga_configure_resource_item_types(["boost", "lives"]);
The following limitations apply:
- You can have a maximum of 20 resource item types.
- Each resource item type string must only contain alphanumeric characters.
Set custom dimensions
Read more about custom dimensions here.
GameAnalytics allows you to create up to 3 custom dimensions for your events. Set up a whitelist of available values before initializing the SDK:
ga_configure_dimensions_01(["ninja", "samurai"]);
ga_configure_dimensions_02(["whale", "dolphin"]);
ga_configure_dimensions_03(["horde", "alliance"]);
Then, during the game, set the active value for each dimension:
ga_set_custom_dimension_01("ninja");
ga_set_custom_dimension_02("whale");
ga_set_custom_dimension_03("horde");
// reset custom dimension 3
ga_set_custom_dimension_03("");
Once a dimension is set it will persist across sessions and automatically be added to all event categories. Set it before initializing the SDK (but after setting the available dimensions) if you want it to be included on the first session start event.
Custom event fields
There is no global setter for custom fields. Instead, every event function takes two optional trailing arguments: a fields JSON object string and a mergeFields boolean.
var fields = json_stringify({ "my_custom_key": "my_custom_value" });
ga_add_design_event("kill:boss:dragon", fields);
Custom fields are not shown on the regular dashboards. They can only be viewed through PipelineIQ's Data Export and Data Warehouse features.
Session handling
Sessions are the concept of a user spending focused time in your game, from game launch to the user leaving the game. Session handling is automatic by default.
On Android, iOS and HTML5, a new session starts when the game launches (or returns to the foreground) and ends once the game is backgrounded.
On Windows, macOS and Linux there is no reliable "going to background" signal, so call ga_on_quit() in the Game End event to close the session before the game exits:
// Game End event
ga_on_quit();
Manual session handling
The default session handling should suffice in most cases and is recommended. It is also possible to handle sessions manually if necessary.
Do not use manual session handling unless it is absolutely necessary. If sessions are not handled accurately this will result in inaccurate and skewed metrics being reported!
Enable it before calling ga_initialize:
ga_set_manual_session_handling(true);
You are then responsible for starting and ending sessions yourself:
ga_start_session();
// ...play the session and send events
ga_end_session();
Error submission
You can enable automatic error submission to catch native unhandled exceptions and submit them to GameAnalytics as error events.
ga_set_error_reporting(true);
ga_set_error_reporting is only implemented on Windows, macOS and Linux.
After a game has been launched it will only send a maximum of 10 error events automatically. Some games can generate a lot of exceptions and this cap prevents degraded performance and unintended bandwidth usage.
You can also submit your own custom error events at any time with ga_add_error_event.