Skip to main content
The LanderLab Quiz Events API publishes the lifecycle of your quiz so you can interact with it using custom JavaScript. This is particularly useful if you want to implement your own granular tracking or if you want to interact with your quiz data client-side.

Introduction

The Events API allows you to listen to different lifecycle events of your quiz and execute custom code when these events occur. Here’s a basic example:
where ll-quiz-init is the Event Name of the lifecycle event.

Events Overview

Your quiz emits the following events per lifecycle event:

ll-quiz-init Event

When: When the quiz loads initially and is bound to the DOM. Event Detail:
  • quizId (string): The unique identifier of the quiz
  • llQuizApi (LlQuizApi): The LlQuiz API instance for interacting with the quiz
Example:

ll-quiz-submit Event

When: When the quiz gets submitted (typically when the submit button is clicked and the form is successfully submitted). Event Detail:
  • quizId (string): The unique identifier of the quiz
  • stepId (string): The step ID where submission occurred
  • stepName (string): The step name where submission occurred
  • fields (Field[]): Array of field objects with detailed information (see Fields Structure below)
  • fieldsSimple (FieldsSimple): Key-value object with label as key and value as string (see FieldsSimple Structure below)
  • llQuizApi (LlQuizApi): The LlQuiz API instance for interacting with the quiz
  • response (any): The API response from the submission endpoint. Can be:
    • The parsed JSON response if the API returns JSON
    • The Response object if it’s not JSON
    • null if the API call failed
Example:

ll-quiz-step-view Event

When: When a step is visited (whenever the user navigates to a new step). Event Detail:
  • quizId (string): The unique identifier of the quiz
  • stepId (string): The step ID that was viewed
  • stepName (string): The step name that was viewed
  • fields (Field[]): Array of field objects from the current step (see Fields Structure below)
  • fieldsSimple (FieldsSimple): Key-value object with label as key and value as string for the current step (see FieldsSimple Structure below)
  • llQuizApi (LlQuizApi): The LlQuiz API instance for interacting with the quiz
Example:

ll-quiz-step-leave Event

When: When navigating away from a step (before the next step is shown). Event Detail:
  • quizId (string): The unique identifier of the quiz
  • stepName (string): The step name being left
  • llQuizApi (LlQuizApi): The LlQuiz API instance for interacting with the quiz
Example:

ll-quiz-exit Event

When: When the tab/window in which the quiz lives gets closed. This event is based on the native pagehide event, which, unfortunately, is not entirely reliable. The event may not fire in all scenarios (e.g., force quit, browser crash, or certain mobile browser behaviors). Don’t rely on it for critical operations. Event Detail:
  • quizId (string): The unique identifier of the quiz
  • llQuizApi (LlQuizApi): The LlQuiz API instance for interacting with the quiz
Example:

ll-quiz-button-click Event

When: When a button block is clicked. This includes DefaultButton, Continue, Previous, and Submit button blocks. Event Detail:
  • quizId (string): The unique identifier of the quiz
  • blockId (string): The unique identifier of the button block that was clicked
  • blockName (string): The name property of the button block
  • stepId (string): The step ID where the button is located
  • stepName (string): The step name where the button is located
  • llQuizApi (LlQuizApi): The LlQuiz API instance for interacting with the quiz
Example:

ll-quiz-input-click Event

When: When a Multiple Choice option or Image Choice option is clicked. Event Detail:
  • quizId (string): The unique identifier of the quiz
  • blockId (string): The unique identifier of the block where the option was clicked
  • blockName (string): The name property of the block
  • stepId (string): The step ID where the block is located
  • stepName (string): The step name where the block is located
  • optionId (string): The unique identifier of the clicked option
  • optionValue (string): The value of the clicked option
  • optionLabel (string): The label of the clicked option
  • llQuizApi (LlQuizApi): The LlQuiz API instance for interacting with the quiz
Example:

Understanding fields and fieldsSimple

fields and fieldsSimple contain all information from your quiz in different structures. Quick Overview:
  • fieldsSimple: A key-value object where keys are field labels and values are user inputs as strings
  • fields: An array of detailed field objects with complete metadata (id, label, value, key, stepId, stepName)
Quick Example:

Using LlQuiz API in Events

All events provide access to the llQuizApi instance, which allows you to interact with your quiz programmatically. Available Methods:
  • llQuizApi.getCurrentStepID() – Returns the current step ID (e.g., “step-1”)
  • llQuizApi.getCurrentStepName() – Returns the current step name (e.g., “start”)
  • llQuizApi.getBlocks() – Returns all blocks in the quiz
  • llQuizApi.getBlockByID(blockId) – Returns a specific block by its ID
  • llQuizApi.getBlockByName(blockName) – Returns a block by its name property (first match)
  • llQuizApi.getBlocksByStepID(stepId) – Returns all blocks in a specific step
  • llQuizApi.getBlocksByStepName(stepName) – Returns all blocks in a specific step
Block Methods: Most blocks support:
  • block.getValue() – Get the current value of the block
  • block.setValue(value) – Set the value of the block
  • block.reset() – Reset the block to its initial state
Example:

Complete Example

Here’s a complete example showing how to use all quiz events together: