Skip to main content

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 a type — either Record or Counter. An event's type is chosen when it is created and cannot be changed later.

  • Record — logged individually as each event occurs. A record can carry 1 to 5 named integer properties that add detail to the log. Up to 10 records can be logged per deck play.
  • Counter — incremented during a deck play and logged once at the end. Counters carry no properties, but there is no per-play limit on how many times they can be incremented.

Events can be used across multiple decks. Each event is assigned a numeric ID automatically, which is listed in the Analytics tab and is used when logging events from scripts.

Logging events

There are two ways to log an analytics event during gameplay:

Using a response

For a Record event, add the Log an analytics record 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 record "LevelFinished"
level = $currentLevel
score = $score
timeSeconds = $elapsedTime

For a Counter event, add the Log an analytics counter response and select the event. Each time the response fires during a play, the counter is incremented by one; the total is logged automatically when the play ends.

When this actor collides with any "Coin":
Log an analytics counter "CoinsCollected"

Using a script

Use castle.logAnalyticsRecord or castle.logAnalyticsCounter in a Lua script:

local LEVEL_FINISHED = 1482  -- copy this ID from the Analytics tab
castle.logAnalyticsRecord(LEVEL_FINISHED, currentLevel, score, elapsedTime)

local COINS_COLLECTED = 1521
castle.logAnalyticsCounter(COINS_COLLECTED)

Limits

At most 10 records can be logged per deck play. Counters have no per-play limit on increments.

Events logged while a creator is playing their own deck are not included in stats.

For simple counts of how often an action occurs, a Counter event is usually the easiest choice. If you also need additional context alongside the count (such as the level reached or time elapsed), use a Record event and store the count in a Variable, then send it in a single record upon an applicable trigger.

When this receives a message "game over":
Log an analytics record "GameStats"
jumps = $jumpCount
deaths = $deathCount