Setup
The Defold SDK includes platform support for iOS, Android, HTML5, Windows, Linux and Mac.
Requirements
- Defold: 1.2.108+
- iOS: iOS 7+
- Android: Android API Level 14
Build size
The SDK contain support for all platforms and CPU architectures. Note that the download size differ from the actual build size. The additional size of adding GameAnalytics depend on the platform, but it is often very low. For Android it could be as low as 50kb depending on what standard libraries are already included in the game/app.
Installation
Github Repository
To install the SDK add these links to the project dependencies (this will always get the latest version):
Or to get a specific version use a link like this (this example will get version 1.0.0): https://github.com/GameAnalytics/GA-SDK-DEFOLD/archive/1.0.0.zip
Configuring game.project
The game.project
file must configured before using the SDK. The available configuration options are listed here.
- Game Key + Secret Key
- Build (optional)
- Custom dimensions (optional)
- Resource Currency and Item Types (optional)
- Use custom user id (optional)
- Use manual session handling (optional)
- Logging
- Enable/disable event submission
- Enable/disable error reporting
- Writable path (only desktop platforms)
Remember to create new section for the SDK in the game.project
file:
[gameanalytics]
Game Key + Secret Key
For each platform you need to configure a set of game keys:
- game key is a unique identifier for your game.
- secret key is used to protect event data from being tampered with as it travels to the GameAnalytics servers.
Notice there is a specific entry for each platform:
[gameanalytics]
game_key_ios = IOS_GAME_KEY
secret_key_ios = IOS_SECRET_KEY
game_key_android = ANDROID_GAME_KEY
secret_key_android = ANDROID_SECRET_KEY
game_key_html5 = HTML5_GAME_KEY
secret_key_html5 = HTML5_SECRET_KEY
game_key_osx = OSX_GAME_KEY
secret_key_osx = OSX_SECRET_KEY
game_key_windows = WINDOWS_GAME_KEY
secret_key_windows = WINDOWS_SECRET_KEY
game_key_linux = LINUX_GAME_KEY
secret_key_linux = LINUX_SECRET_KEY
Build
Build is used to specify the current version of your game. Recommended to use a 3 digit version like [major].[minor].[patch]
. Notice there is a specific entry for each platform:
[gameanalytics]
build_ios = 0.1
build_android = 0.1
build_html5 = 0.1
build_osx = 0.1
build_windows = 0.1
build_linux = 0.1
Auto detect app version to use for build field
There is an option to auto detect app version to use for build field but it is only supported for Android and iOS platforms. The feature is enabled like this:
[gameanalytics]
auto_detect_app_version = 1
Custom Dimensions
During gameplay it is possible to set values for 3 different custom dimensions. For each custom dimension it is needed specify a whitelist. You cannot set a custom dimension value unless it is specified here first.
For more information about Custom Dimensions go here.
The dimensions are comma-seperated like shown in the example (remember no space in between each entry):
[gameanalytics]
custom_dimensions_01 = ninja,samurai
custom_dimensions_02 = whale,dolphin
custom_dimensions_03 = horde,alliance
Resource Currency and Item Types
When submitting resource events you specify a resource currency and resource item type. It is needed to specify a whitelist for each of these. You cannot submit a resource event using other values than specified here.
Each resource currency string should only contain [A-Za-z] characters.
The currencies and item types are comma-seperated like shown in the example (remember no space in between each entry):
[gameanalytics] resource_currencies = gold,gems resource_item_types = boost,lives
Custom Id
The SDK will automatically generate a user id and this is perfectly fine for almost all cases.
Sometimes it is useful to supply this user_id manually – for example if you download raw data for processing and need to match your internal user id (could be a database index on your user table) to the data collected through GameAnalytics.
Do not use a custom userId unless you have a specific need for using it.
Note that if you introduce this into a game that is already deployed (using the automatic id) it will start counting existing users as new users and your metrics will be affected. Use this from the start of the game lifetime.
When using custom id you need to remember GameAnalytics will first be fully initialized when you have set the custom id. No events can be sent before GameAnalytics is fully initialized.
To enable custom user id, add this to the game.project file:
[gameanalytics]
use_custom_id = 1
To set custom user id in the game call this from your script:
gameanalytics.configureUserId( "my_custom_id" )
Use manual session handling
To enable manual session handling, add this to the game.project
file:
[gameanalytics]
use_manual_session_handling = 1
To manual enable or disable session handling later on call this:
gameanalytics.setEnabledManualSessionHandling(true)
Read more about sessions here including manual session handling.