Event Tracking
GameAnalytics features the following event types:
| Event | Description |
|---|---|
| Ad | Ads shown and clicked, fill rate. |
| Business | In-App Purchases supporting receipt validation on GA servers. |
| Design | Submit custom event id’s. Useful for tracking metrics specifically needed for your game. |
| Error | Submit exception stack traces or custom error messages. |
| Health | Automatically submits health metrics related to your game such as FPS. |
| Impression | Impression data from different ad networks |
| Progression | Level attempts with Start, Fail & Complete event. |
| Resource | Managing the flow of virtual currencies - like gems or lives |
Read more about events here
Every event function takes a table of options. A missing or wrong option raises a Lua error, so mistakes show up during development.
All event functions accept two optional keys on top of the ones listed below:
| Field | Type | Description |
|---|---|---|
| customFields | string | A JSON string of key-value pairs attached to this event only |
| mergeFields | boolean | true to merge the fields with the global custom event fields, false (the default) to replace them |
Business Events
Business events track in-app purchases made with real money.
| Field | Type | Required | Description | Example |
|---|---|---|---|---|
| currency | string | yes | Currency code in ISO 4217 format | USD |
| amount | integer | yes | Amount in cents | 99 is $0.99 |
| itemType | string | yes | The type/category of the item | GoldPacks |
| itemId | string | yes | Specific item bought | 1000GoldPack |
| cartType | string | no | The game location of the purchase. Max 10 unique values | EndOfLevel |
| receipt | string | no | The transaction receipt, for validation |
gameanalytics.addBusinessEvent({
currency = "USD",
amount = 99,
itemType = "boost",
itemId = "megaBoost",
cartType = "shop",
})
Receipt validation
Mobile games can be hacked and distributed illegally. Hacking an app will often involve faking all purchase requests, which results in business events for transactions that never occurred. GameAnalytics provides receipt validation for each purchase sent to the servers, so revenue metrics reflect the actual spending in your game.
Some configuration is needed before receipt validation is active. Read about validation and the requirements for each platform here.
Receipt validation is supported on the App Store (iOS) and Google Play (Android). Add the store receipt to the event:
| Field | Type | Platform | Description |
|---|---|---|---|
| receipt | string | iOS | The App Store receipt as a base64 string |
| autoFetchReceipt | boolean | iOS | true to let the SDK read the App Store receipt itself |
| receipt | string | Android | The purchase data (INAPP_PURCHASE_DATA) of the transaction |
| signature | string | Android | The purchase signature (INAPP_DATA_SIGNATURE) |
local info = sys.get_sys_info()
if info.system_name == "iPhone OS" then
gameanalytics.addBusinessEvent({
currency = "USD",
amount = 99,
itemType = "boost",
itemId = "megaBoost",
cartType = "shop",
autoFetchReceipt = true,
})
elseif info.system_name == "Android" then
gameanalytics.addBusinessEvent({
currency = "USD",
amount = 99,
itemType = "boost",
itemId = "megaBoost",
cartType = "shop",
receipt = "<purchase data>",
signature = "<signature>",
})
end
If the receipt or signature is missing or invalid the event is still submitted, but it registers as not validated. On platforms other than iOS and Android the event is sent without the receipt.
For more information on Business Events go here.
Resource Events
Resource events register the flow of your in-game economy (virtual currencies): the Source (add) and the Sink (subtract) of each currency.
The currencies and item types used in resource events must be registered in game.project first. See Resources.
| Field | Type | Required | Description |
|---|---|---|---|
| flowType | string | yes | "Source" to add or "Sink" to subtract the resource |
| currency | string | yes | One of the currencies in resource_currencies. Letters only ([A-Za-z]) |
| amount | number | yes | Amount sourced or sunk, always positive |
| itemType | string | yes | One of the item types in resource_item_types |
| itemId | string | yes | The name of the item |
Source (add) gems from an in-app purchase:
gameanalytics.addResourceEvent({
flowType = "Source",
currency = "gems",
amount = 400,
itemType = "IAP",
itemId = "Coins400",
})
Sink (subtract) gems to buy an item:
gameanalytics.addResourceEvent({
flowType = "Sink",
currency = "gems",
amount = 400,
itemType = "Weapons",
itemId = "SwordOfFire",
})
Trading one virtual currency for another is two events, a Sink of the currency spent and a Source of the currency received:
gameanalytics.addResourceEvent({
flowType = "Sink",
currency = "gems",
amount = 100,
itemType = "Boosters",
itemId = "BeamBooster5Pack",
})
gameanalytics.addResourceEvent({
flowType = "Source",
currency = "BeamBooster",
amount = 5,
itemType = "Gems",
itemId = "BeamBooster5Pack",
})
Be careful not to call the resource event too often!
In a game where the player collects coins fast you should not send a Source event on each pickup. Count the coins instead and send a single Source event when the player completes or fails the level.
For more information on Resource Events go here.
Progression Events
Progression events track attempts at completing a part of the game (level, area). An area follows a 3 tier hierarchy (for example world:stage:level) describing what the player is trying to complete.
Send a Start event when the attempt begins, and a Complete or Fail event when it ends, with a score if needed.
| Field | Type | Required | Description |
|---|---|---|---|
| progressionStatus | string | yes | "Start", "Complete" or "Fail" |
| progression01 | string | yes | 1st progression tier |
| progression02 | string | no | 2nd progression tier |
| progression03 | string | no | 3rd progression tier, only allowed when progression02 is set |
| score | number | no | Score of the attempt, usually sent with Complete or Fail |
gameanalytics.addProgressionEvent({
progressionStatus = "Start",
progression01 = "world01",
progression02 = "stage01",
progression03 = "level01",
})
gameanalytics.addProgressionEvent({
progressionStatus = "Complete",
progression01 = "world01",
progression02 = "stage01",
progression03 = "level01",
score = 1200,
})
It is not required to use all 3 tiers if your game does not have them, but they must be filled in order:
- progression01
- progression01 and progression02
- progression01, progression02 and progression03
For more information on Progression Events go here.
Error Events
Error events send manual error reports to GameAnalytics. Group them by severity and attach a message.
| Field | Type | Required | Description |
|---|---|---|---|
| severity | string | yes | "Debug", "Info", "Warning", "Error" or "Critical" |
| message | string | yes | The error message or stack trace |
gameanalytics.addErrorEvent({
severity = "Debug",
message = "Something went bad in some of the smelly code!",
})
Unhandled errors and crashes are sent automatically when error reporting is enabled, so this is only for errors the game catches itself.
For more information on Error Events go here.
Design Events
Every game is special, so some events you need might not be covered by the other event types. The design event lets you add your own event id hierarchy.
| Field | Type | Required | Description |
|---|---|---|---|
| eventId | string | yes | 1 to 5 segments separated by :, each segment at most 64 characters |
| value | number | no | Optional custom value. Makes mean and sum aggregations available on top of the count |
gameanalytics.addDesignEvent({ eventId = "Kill:Sword:Robot" })
gameanalytics.addDesignEvent({
eventId = "BossFights:FireLord:KillTimeUsed",
value = 234,
})
Custom dimensions and progression filters are not added to design and error events, so you cannot filter by them when viewing design or error metrics.
It is important not to generate an excessive amount of unique nodes in the event hierarchy tree.
A bad implementation example: [level_name]:[weapon_used]:[damage_done]
level_name could be 100 values, weapon_used 300 values and damage_done 1 to 5000. That is 100 * 300 * 5000 = 1.5M possible nodes, which is far too many. Continuous values like damage belong in the event value, not in the event string. The maximum amount of unique nodes should be around 10k.
Ad Events
Ad events are only sent on Android and iOS.
Ad events track what happens with the ads shown by your ad SDK. Call them from the ad SDK's callbacks, for example when an ad is shown, clicked or fails to load.
| Field | Type | Required | Description |
|---|---|---|---|
| adAction | string | yes | "Clicked", "Show", "FailedShow" or "RewardReceived" |
| adType | string | yes | "Video", "RewardedVideo", "Playable", "Interstitial", "OfferWall" or "Banner" |
| adSdkName | string | yes | Name of the ad or ad mediation SDK, all lower-case with no spaces (for example admob, unityads, ironsource) |
| adPlacement | string | yes | Identifier of the ad in the game or its placement |
| duration | number | no | How long the player watched a video or rewarded video ad, in milliseconds |
| noAdReason | string | no | Why no ad was shown: "Unknown", "Offline", "NoFill", "InternalError", "InvalidRequest" or "UnableToPrecache" |
Track an interstitial when it is shown, and when the player clicks it:
gameanalytics.addAdEvent({
adAction = "Show",
adType = "Interstitial",
adSdkName = "admob",
adPlacement = "level_end",
})
gameanalytics.addAdEvent({
adAction = "Clicked",
adType = "Interstitial",
adSdkName = "admob",
adPlacement = "level_end",
})
Track a rewarded video with how long it was watched, and the reward being granted:
gameanalytics.addAdEvent({
adAction = "Show",
adType = "RewardedVideo",
adSdkName = "admob",
adPlacement = "shop",
duration = 30000,
})
gameanalytics.addAdEvent({
adAction = "RewardReceived",
adType = "RewardedVideo",
adSdkName = "admob",
adPlacement = "shop",
})
Track an ad that could not be shown, with the reason reported by the ad network:
gameanalytics.addAdEvent({
adAction = "FailedShow",
adType = "RewardedVideo",
adSdkName = "admob",
adPlacement = "shop",
noAdReason = "NoFill",
})
Custom Event Fields
Any event can carry its own custom fields, a JSON string of key-value pairs that is only available through raw data export:
gameanalytics.addDesignEvent({
eventId = "shop:opened",
customFields = json.encode({ source = "main_menu", coins = 120 }),
})
See Custom Event Fields for global fields and merging.
Find more information on Custom Event Fields and Data Export following the links.