Get Started
The GameAnalytics Defold SDK is a native extension. Add it as a project dependency, put your keys in game.project, and the gameanalytics Lua module is ready to use in every script.
Before you start
You need a game in your GameAnalytics account and its game key and secret key for every platform you build for. The keys are found in the game's settings in the GameAnalytics dashboard.
The SDK supports the following platforms:
| Platform | Requirement |
|---|---|
| Defold | 1.14 or newer |
| iOS | 12.0 or newer, on devices and the simulator |
| Android | 5.0 (API level 21) or newer |
| Desktop | macOS (Apple silicon and Intel), Windows 64-bit, Linux 64-bit |
| Web | HTML5 (wasm-web) |
Version 5.0.0 no longer needs the defold-openssl dependency. If you are upgrading from 4.x, remove it from your project dependencies. 32-bit Windows, 32-bit iOS and the js-web target are no longer supported, following Defold.
Install the SDK
-
Open
game.projectin the Defold editor and add the SDK under Project > Dependencies:https://github.com/GameAnalytics/GA-SDK-DEFOLD/archive/refs/tags/<version>.zipReplace
<version>with the release you want, for example5.0.0. -
Select Project > Fetch Libraries.
That is all the installation needed. The extension bundles the native GameAnalytics SDKs for every platform, including the JavaScript SDK and the HTML template entry for web builds.
Integrate the SDK
Add the SDK to your project
The gameanalytics module is a global in all your Lua scripts once the dependency is fetched. There is nothing to require:
gameanalytics.addDesignEvent({ eventId = "tutorial:start" })
Configure the SDK
All configuration lives in a [gameanalytics] section of game.project. Open the file in a text editor and add your keys. Each platform has its own game in GameAnalytics, so keys and build versions are set per platform (ios, android, html5, osx, windows, linux):
[gameanalytics]
game_key_ios = <your iOS game key>
secret_key_ios = <your iOS secret key>
game_key_android = <your Android game key>
secret_key_android = <your Android secret key>
game_key_html5 = <your web game key>
secret_key_html5 = <your web secret key>
build_ios = 1.0.0
build_android = 1.0.0
build_html5 = 1.0.0
enable_info_log = 1
Only add the keys for the platforms you build for. The Configuration page lists every available setting.
Initialize the SDK
By default the extension starts GameAnalytics as soon as the game starts, using the keys from game.project. No code is needed.
If you want to decide when the SDK starts, for example after asking the player for consent or after registering a remote configs listener, enable manual initialization:
[gameanalytics]
manual_initialize = 1
Then start the SDK from your script:
gameanalytics.initialize()
Settings that must be in place before the SDK starts, such as the available custom dimensions and resource currencies, are read from game.project. Set them there rather than at runtime.
Sending events
Every event function takes a table of options. A missing or wrong option raises a Lua error, so mistakes show up during development:
gameanalytics.addProgressionEvent({
progressionStatus = "Complete",
progression01 = "world1",
progression02 = "level1",
score = 1200,
})
The Event Tracking page covers every event type.
Web builds
The extension adds the GameAnalytics.js script tag to Defold's HTML template automatically. If your game uses its own HTML template, add this line to its <head>:
<script type="text/javascript" src="GameAnalytics.js"></script>
Platform notes
- Android: error reporting (
enable_error_reporting = 1) needs theandroidx.corelibrary, which games usually get from another extension. The SDK leaves out Google's App Set ID library, so App Set IDs are only sent when another extension already includesplay-services-appset. - iOS: the SDK ships its privacy manifest (
PrivacyInfo.xcprivacy), which Defold adds to your app. - Web: external user ids and session times are not available and return empty values or 0.
setEnabledEventSubmissionhas no effect. - Desktop: requests go through Defold's own HTTP client, so no extra libraries are needed.