What are xAPI Extensions and How Do I Use Them in My xAPI Statements?

What are xAPI Extensions and How Do I Use Them in My xAPI Statements?

Best Practices for xAPI Extensions
Activity, Context, and Result Extensions in xAPI Statements


Do you need to know when and how to best use Activity, Context or Result Extensions in your xAPI Statements? This is a common challenge and a frequently asked question we receive from both content developers and LRS data wranglers. 

What are xAPI Extensions? You can read more about them in the xAPI 2.0 IEEE Standard. In a nutshell, they allow you to add custom learning experience data to your xAPI statements, providing richer context beyond the core data model. 

Here are some key things to remember about using xAPI Extensions:
  1. Extensions are user-defined (represented as JSON data)
  2. The Key (or property name) of an Extension must be an IRI
  3. The Value of Extension can be any string value or JSON Object
  4. It can only be used in specific parts of an xAPI Statement, including:
  5. Activity (object.definition.extensions)
  6. Result (result.extensions)
  7. Context (context.extensions)

Activity Extensions

What is an Activity Extension? The Activity Object Definition part of an xAPI Statement contains metadata about the Object. When used as part of the Activity Object Definition, the Extensions Object provides a way to optionally extend xAPI Statements to include additional information about the activity (object). 

For example, you may want to specify the type of assessment object (e.g., pretest, posttest, survey, quiz, etc) used in an xAPI Statement to more easily query the data and build meaningful charts and dashboards showing a comparison of the pretest and posttest results. In the example below, an “assessment-type” Activity Extension is defined for the assessment object. The property name for the extension is “http://id.tincanapi.com/extension/assessment-type” and the value of the extension is “posttest.” Since the value of this extension is not expected to ever change for this specific assessment object, then this is an ideal way to use an Activity Extension in an xAPI Statement. 

Best Practice

You should not store dynamic values in Activity Extensions since it is expected that these values are static and should not change. In Veracity’s LRS, Activity Extensions are canonicalized for this reason. 

Example

"object": {
    "id": "https://example.com/activities/assessments/17923a7d-afee-22aa-c4ee-3333acac400",
    "definition": {
      "name": {
        "en": "IT Fundamentals Test"
      },
      "description": {
        "en": "The IT Fundamentals Test assesses the learner’s knowledge of basic IT concepts and terminology."
      },
      "type": "http://adlnet.gov/expapi/activities/assessment",
      "extensions": {
        "http://id.tincanapi.com/extension/assessment-type": "posttest"
      }
    }
  }



Context Extensions

What is a Context Extension? The Context part of an xAPI Statement contains additional information related to a learning experience or event. When used as part of the Context, the Extensions Object provides a way to optionally extend xAPI Statements to include additional information about the broader learning experience or interaction that the Statement is representing. 

For example, the xAPI Video Profile provides a “volume” Context Extension for representing the volume loudness in a video (or other media). This value must be able to change (float value between 0 and 1) in an xAPI Statement since the user can typically change the volume when a video is played. An example of the JSON for the Context Object Extension part of an xAPI statement is provided below. 

Best Practice

You should not store static values in Context Extensions since it is expected that these values may need to change. In Veracity’s LRS, Context Extensions are not canonicalized for this reason. 

Example

  "object": {
    "id": "https://www.youtube.com/watch?v=DoN0XDeSthg",
    "definition": {
      "name": {
        "en-US": "Video"
      },
      "description": {
        "en-US": "An Introduction to xAPI Video"
      },
      "type": "https://w3id.org/xapi/video/activity-type/video"
    },
    "objectType": "Activity"
  },
  "context": {
    "contextActivities": {
      "category": [
        {
          "id": "https://w3id.org/xapi/video"
        }
      ]
    },
    "extensions": {
      "https://w3id.org/xapi/video/extensions/volume": 0.5
    },
    "registration": "39be826d-9ff6-57f9-b429-99cb0c389267"
  }  


Result Extensions

What is a Result Extension? The Result part of an xAPI Statement contains additional information related to an outcome. It doesn’t have to be a learning outcome. Let’s imagine you want to track other types of results beyond what is typically associated with learning (e.g., completion, scores, pass/fail, etc). You can also use Result Extensions to store this additional data. 

For example, the xAPI Video Profile provides a “time” Result Extension for storing the specific time position in a video as a result of the user interacting, pausing, playing, or terminating the video. This value is dynamically generated and expected to change in each xAPI Statement. An example of the JSON for the Result Object Extension part of an xAPI statement is provided below. 

Best Practice

You should not store static values in Result Extensions since it is expected that these values may need to change based on some type of interaction with the object. In Veracity’s LRS, Result Extensions are not canonicalized for this reason. 

Example

  "object": {
    "id": "https://www.youtube.com/watch?v=DoN0XDeSthg",
    "definition": {
      "name": {
        "en-US": "Video"
      },
      "description": {
        "en-US": "An Introduction to xAPI Video"
      },
      "type": "https://w3id.org/xapi/video/activity-type/video"
    },
    "objectType": "Activity"
  },
  "result": {
    "extensions": {
      "https://w3id.org/xapi/video/extensions/time": 0.144
    }
  }


Related Resources

Looking for more examples on using xAPI Extensions? Need to build reports, graphs, or other dashboard visualizations over your custom data using xAPI Extensions? Check out the related video resources (below) from YouTube:
  1. Using xAPI Extensions
  2. Building Reports with xAPI Extensions
  3. Building Graphs with xAPI Extensions
  4. xAPI Extensions: The Missing Key To The Extra Data You Need