Skip to content

Events ​

The platform emits browser CustomEvents on window. All events are prefixed with mindtraining: and their payload is always available in event.detail.


mindtraining:ready ​

Fired when: the script has finished loading and the global MindtrainingPlatform API is available on window.

When to use: this is the recommended hook to call init. By listening to this event you avoid race conditions between the script loading and your initialization code running.

event.detail

FieldTypeDescription
apiobjectReference to window.MindtrainingPlatform
js
window.addEventListener('mindtraining:ready', function (event) {
  // event.detail.api === window.MindtrainingPlatform
  MindtrainingPlatform.init('mindtraining', {
    viewer: { loggedIn: false },
  })
})

Script already loaded? If your listener is registered after the script has already executed, the event won't fire again. Use this guard pattern:

js
function initializeMindtraining() {
  MindtrainingPlatform.init('mindtraining', {
    viewer: { loggedIn: false },
  })
}

if (window.MindtrainingPlatform) {
  initializeMindtraining()
} else {
  window.addEventListener('mindtraining:ready', initializeMindtraining, { once: true })
}

mindtraining:sdk:loaded ​

Emitted once after init(), when the platform’s initial content is displayed, including when opening a game directly. Use it to hide your page’s loading indicator. Register the listener before calling init(); late listeners do not receive the event. Navigation and updateConfig() do not emit it again. Images and fonts may still be loading. Use mindtraining:game:loaded to know when a game is ready.

The payload contains api (the platform API), container (the initialized HTML element), and pathname (the path of the initial platform page).

js
window.addEventListener('mindtraining:sdk:loaded', function (event) {
  // The initial content is rendered; hide the host loading indicator.
  document.getElementById('host-loader')?.remove()
  console.log(event.detail.pathname)
})

mindtraining:config ​

Fired when: the platform configuration is updated — both after the initial init() call and after any subsequent updateConfig() call.

When to use: use this event to react to configuration changes from outside the platform, such as synchronizing your own UI state (e.g. reflecting a subscription change or login state update that the platform just received).

event.detail

The full normalized PlatformInitConfig object at the time of the change.

FieldTypeDescription
viewerobjectCurrent viewer/user settings
viewer.userIdstring | nullThe active user ID
viewer.loggedInbooleanWhether the user is authenticated
viewer.subscribedbooleanWhether the user has an active subscription
uiobjectCurrent UI settings
ui.mode'web' | 'app'Rendering mode
ui.actionsobjectRegistered action callbacks
accessobjectCurrent access rules per game type
js
window.addEventListener('mindtraining:config', function (event) {
  const config = event.detail

  console.log('User logged in:', config.viewer?.loggedIn)
  console.log('User subscribed:', config.viewer?.subscribed)
  console.log('Active access rules:', config.access?.games)
})

Game and navigation events ​

The following events are emitted during gameplay and navigation. Use them for analytics, tracking, host-side integrations, and observability.


mindtraining:game:loaded ​

Fired when: a game session or game screen is ready for user interaction.

When to use: use this event to track internal game pageviews, measure which games actually load, or trigger host-side logic based on game type.

event.detail

FieldTypeDescription
gameTypestringGame type (e.g. crossword, sudoku)
gameIdstringUnique game identifier
variantstringGame variant (e.g. default, mini)
routestringInternal route path
sourcestringSource of the game (e.g. today, archive)
js
window.addEventListener('mindtraining:game:loaded', function (event) {
  Analytics.track('mindtraining_game_loaded', event.detail)
})

mindtraining:game:playing ​

Fired when: the game starts after the user presses Play or the configured flow starts it automatically.

When to use: use this event to distinguish between a loaded game and a started game session. Use mindtraining:game:first-interaction to measure the user's first gameplay input.

event.detail

FieldTypeDescription
gameTypestringGame type
gameIdstringUnique game identifier
variantstringGame variant
startedAtstringISO 8601 timestamp when play started
js
window.addEventListener('mindtraining:game:playing', function (event) {
  Analytics.track('mindtraining_game_playing', event.detail)
})

mindtraining:game:first-interaction ​

Fired when: the user performs the first gameplay keyboard input or click after the game has started. It fires once per game session.

When to use: use this event to measure activation latency and distinguish keyboard interaction from click interaction.

event.detail

FieldTypeDescription
gameTypestringGame type
gameIdstringUnique game identifier
variantstringGame variant
interactionType'keyboard' | 'click'Type of the first interaction
timenumberCurrent game timer value in seconds; for Tiles and other countdown games, this is the remaining time
initialTimenumberInitial countdown duration in seconds; included only for countdown games such as Tiles
interactedAtstringISO 8601 timestamp of the first interaction
js
window.addEventListener('mindtraining:game:first-interaction', function (event) {
  Analytics.track('mindtraining_game_first_interaction', event.detail)
})

mindtraining:game:completed ​

Fired when: the user finishes a game successfully.

When to use: use this event for complete funnels, difficulty analytics, or host-side ranking and gamification.

event.detail

FieldTypeDescription
gameTypestringGame type
gameIdstringUnique game identifier
variantstringGame variant
completedAtstringISO 8601 timestamp when play ended
durationMsnumberDuration of the session in milliseconds
scorenumberFinal score (if applicable)
js
window.addEventListener('mindtraining:game:completed', function (event) {
  Analytics.track('mindtraining_game_completed', event.detail)
})

mindtraining:game:abandoned ​

Fired when: the user leaves a game session after play has started and before completing it.

When to use: use this event to detect friction, measure drop-off by game or variant, or improve retention flows.

event.detail

FieldTypeDescription
gameTypestringGame type
gameIdstringUnique game identifier
variantstringGame variant
durationMsnumberTime spent before abandoning
progressnumberProgress (0–1) at abandonment
js
window.addEventListener('mindtraining:game:abandoned', function (event) {
  Analytics.track('mindtraining_game_abandoned', event.detail)
})

mindtraining:game:state:saved ​

Fired when: the game state is persisted (e.g. for “continue playing” functionality).

When to use: use this event to track retention, “continue playing” flows, or verify that saved state is working correctly.

event.detail

js
window.addEventListener('mindtraining:game:state:saved', function (event) {
  Analytics.track('mindtraining_game_state_saved', event.detail)
})

mindtraining:access:blocked ​

Fired when: the platform detects that a surface (today’s game, archive, etc.) is blocked for the user.

When to use: use this event to trigger contextual paywalls, measure unmet demand, or customize host messages based on the blocked reason.

event.detail

js
window.addEventListener('mindtraining:access:blocked', function (event) {
  Analytics.track('mindtraining_access_blocked', event.detail)
  if (event.detail.blockedReason === 'subscription_required') {
    Paywall.show({ context: 'game_archive' })
  }
})

mindtraining:route:changed ​

Fired when: the internal route of the platform changes (e.g. navigation within the SPA).

When to use: use this event for virtual pageviews, or to sync analytics with the platform’s internal navigation.

event.detail

js
window.addEventListener('mindtraining:route:changed', function (event) {
  Analytics.track('mindtraining_route_changed', event.detail)
})

mindtraining:pageview ​

Fired when: the platform registers a navigable view that is relevant for analytics.

When to use: use this event for pageview tracking in analytics tools, reporting by section and game type, or attribution of internal SPA navigation.

event.detail

FieldTypeDescription
pathnamestringCurrent route path
titlestringPage title
gameTypestringGame type (if applicable)
gameIdstringGame identifier (if applicable)
variantstringGame variant (if applicable)
sourcestringSource of the view (e.g. today, archive)
js
window.addEventListener('mindtraining:pageview', function (event) {
  Analytics.track('mindtraining_pageview', event.detail)
})

mindtraining:user:action ​

Fired when: the user performs a key interaction (e.g. clicks archive, selects a game).

When to use: use this event to track relevant clicks, run experiments, or instrument UI without wiring each button from the host.

event.detail

FieldTypeDescription
actionstringAction identifier (e.g. click_archive)
locationstringUI location (e.g. home_header)
gameTypestringGame type (if applicable)
variantstringGame variant (if applicable)
indexnumberZero-based position of the clicked game block/item in its rendered list (if applicable)
urlstringExternal URL selected from navigation (if applicable)

Current action values:

ValueMeaning
click_playUser clicks a play/open game CTA
click_archiveUser clicks an archive/history CTA
click_startUser starts a game from the intermediate screen
click_backUser clicks a back/navigation CTA
click_navUser clicks an external navigation link

Current location values:

ValueSurface
home_block_gameGame card/block on the home screen
home_block_dynamic_gamesDynamic games block on the home screen
historical_game_blockHistorical/recent games block
intermediate_game_screenIntermediate screen shown before entering a game
game_navigationIn-game navigation header
site_navSite navigation menu
game_navigation_menuIn-game navigation menu
js
window.addEventListener('mindtraining:user:action', function (event) {
  Analytics.track('mindtraining_user_action', event.detail)
})

mindtraining:share:requested ​

Fired when: the user attempts to share content from the platform.

When to use: use this event for share-intent analytics, or to bridge with the host app's native share flow.

event.detail

FieldTypeDescription
gameTypestringGame type
gameIdstringGame identifier
urlstringURL to share
titlestringTitle to share
js
window.addEventListener('mindtraining:share:requested', function (event) {
  Analytics.track('mindtraining_share_requested', event.detail)
})

mindtraining:error ​

Fired when: a flow, load, or interaction error occurs that is relevant to the host.

When to use: use this event for observability, alerting, or host-side fallback UI.

event.detail

FieldTypeDescription
scopestringError scope (e.g. game-load)
codestringError code (e.g. GAME_DATA_FETCH_FAILED)
messagestringHuman-readable message
recoverablebooleanWhether the user can recover from the error
js
window.addEventListener('mindtraining:error', function (event) {
  Analytics.track('mindtraining_error', event.detail)
  if (!event.detail.recoverable) {
    ErrorUI.show(event.detail)
  }
})

A practical approach for host analytics is to listen to:

  1. mindtraining:ready - to know when initialization is safe
  2. mindtraining:config - to track configuration changes
  3. mindtraining:game:loaded - to measure game loads
  4. mindtraining:pageview - to track pageviews
  5. mindtraining:game:playing - to measure started game sessions
  6. mindtraining:game:first-interaction - to measure gameplay activation
  7. mindtraining:game:completed - to measure completions
  8. mindtraining:access:blocked - to measure unmet demand
  9. mindtraining:error - to monitor errors
js
window.addEventListener('mindtraining:game:loaded', function (event) {
  Analytics.track('mindtraining_game_loaded', event.detail)
})
window.addEventListener('mindtraining:game:playing', function (event) {
  Analytics.track('mindtraining_game_playing', event.detail)
})
window.addEventListener('mindtraining:game:first-interaction', function (event) {
  Analytics.track('mindtraining_game_first_interaction', event.detail)
})
window.addEventListener('mindtraining:pageview', function (event) {
  Analytics.track('mindtraining_pageview', event.detail)
})
window.addEventListener('mindtraining:access:blocked', function (event) {
  Analytics.track('mindtraining_access_blocked', event.detail)
})

Client integration documentation maintained in-repo.