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: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 user starts real interaction with the game (e.g. first move or input).

When to use: use this event to distinguish between a game loaded and a game actually played, measure activation, or track engagement.

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: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 an active game session without 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

Client integration documentation maintained in-repo.