Analytics
Analytics lets you track events in your Deck so you can understand how players interact with your game. You define events, then log them during gameplay using responses or scripts.
Defining events
To define an event, navigate to a deck under the Create screen and open the Analytics tab. Each event requires a name and can optionally have 1 to 5 named integer properties that carry additional data with each logged event.
Events are creator-scoped — a single event can be used across multiple decks. Each event is assigned a numeric ID automatically, which is listed in the Analytics tab. You can copy it by tapping into the event definition — this ID is used when logging events from scripts.
Logging events
There are two ways to log an analytics event during gameplay:
Using a response
Add the Log an analytics event response to a Rule. Select the event you defined, then fill in the integer property fields. Each property field accepts any Expression, so you can use variables, math, or other dynamic values.
When this receives a message "level complete":
Log an analytics event "LevelFinished"
level = $currentLevel
score = $score
timeSeconds = $elapsedTime
Using a script
Use castle.logAnalyticsEvent in a Lua script:
local LEVEL_FINISHED = 1482 -- copy this ID from the Analytics tab
castle.logAnalyticsEvent(LEVEL_FINISHED, currentLevel, score, elapsedTime)
Limits
At most 10 events can be logged per deck play.
If you want to count the number of times a certain action occurs, we recommend storing the count in a Variable and sending it in a single event upon a trigger (such as game over or level complete). Note that this will not count actions from plays that do not reach the trigger.
When this receives a message "game over":
Log an analytics event "GameStats"
jumps = $jumpCount
deaths = $deathCount