Skip to main content

Event Tracking

GameAnalytics features the following event types:

EventDescription
AdAds shown and clicked, fill rate.
BusinessIn-App Purchases supporting receipt validation on GA servers.
DesignSubmit custom event id’s. Useful for tracking metrics specifically needed for your game.
ErrorSubmit exception stack traces or custom error messages.
HealthAutomatically submits health metrics related to your game such as FPS.
ImpressionImpression data from different ad networks
ProgressionLevel attempts with Start, Fail & Complete event.
ResourceManaging the flow of virtual currencies - like gems or lives
tip

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:

FieldTypeDescription
customFieldsstringA JSON string of key-value pairs attached to this event only
mergeFieldsbooleantrue 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.

FieldTypeRequiredDescriptionExample
currencystringyesCurrency code in ISO 4217 formatUSD
amountintegeryesAmount in cents99 is $0.99
itemTypestringyesThe type/category of the itemGoldPacks
itemIdstringyesSpecific item bought1000GoldPack
cartTypestringnoThe game location of the purchase. Max 10 unique valuesEndOfLevel
receiptstringnoThe transaction receipt, for validation
gameanalytics.addBusinessEvent({
currency = "USD",
amount = 99,
itemType = "boost",
itemId = "megaBoost",
cartType = "shop",
})

Receipt validation​

info

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:

FieldTypePlatformDescription
receiptstringiOSThe App Store receipt as a base64 string
autoFetchReceiptbooleaniOStrue to let the SDK read the App Store receipt itself
receiptstringAndroidThe purchase data (INAPP_PURCHASE_DATA) of the transaction
signaturestringAndroidThe 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
caution

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.

tip

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.

info

The currencies and item types used in resource events must be registered in game.project first. See Resources.

FieldTypeRequiredDescription
flowTypestringyes"Source" to add or "Sink" to subtract the resource
currencystringyesOne of the currencies in resource_currencies. Letters only ([A-Za-z])
amountnumberyesAmount sourced or sunk, always positive
itemTypestringyesOne of the item types in resource_item_types
itemIdstringyesThe 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",
})
danger

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.

tip

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.

FieldTypeRequiredDescription
progressionStatusstringyes"Start", "Complete" or "Fail"
progression01stringyes1st progression tier
progression02stringno2nd progression tier
progression03stringno3rd progression tier, only allowed when progression02 is set
scorenumbernoScore 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
tip

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.

FieldTypeRequiredDescription
severitystringyes"Debug", "Info", "Warning", "Error" or "Critical"
messagestringyesThe 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.

tip

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.

FieldTypeRequiredDescription
eventIdstringyes1 to 5 segments separated by :, each segment at most 64 characters
valuenumbernoOptional 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,
})
caution

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.

danger

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​

info

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.

FieldTypeRequiredDescription
adActionstringyes"Clicked", "Show", "FailedShow" or "RewardReceived"
adTypestringyes"Video", "RewardedVideo", "Playable", "Interstitial", "OfferWall" or "Banner"
adSdkNamestringyesName of the ad or ad mediation SDK, all lower-case with no spaces (for example admob, unityads, ironsource)
adPlacementstringyesIdentifier of the ad in the game or its placement
durationnumbernoHow long the player watched a video or rewarded video ad, in milliseconds
noAdReasonstringnoWhy 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.

tip

Find more information on Custom Event Fields and Data Export following the links.