xAPI (Experience API)
Overview
This document contains a technical explanation on how the xAPI Moodle integration library works.
The Experience API (xAPI) is an e-learning software specification that allows learning content and learning systems to speak to each other in a manner that records and tracks all types of learning experiences.
xAPI defines web services that can be used by any plugin or application to connect to the LMS in a standard way. The main actors in xAPI communication are:
- Client: any plugin or application that wants to use xAPI webservices
- xAPI LRS (server site): responsible for storing and serving the data emitted by the clients
The xAPI LRS specification implements six endpoints:
- The
Statement Endpoint
is used for all xAPI statements. One good aspect about xAPI is that the amount of messages that can be shared between the clients and the LRS is quite limited. The main message type is called Statement and all statements can be summarized as "An actor XX executes action YY on object ZZ".
The typical statement object is a JSON element containing:
- Actor: the person or group that do something
- Verb: the action the Actor do
- Object: the object on the Verb is executed. There are more than one type of objects that can be defined here but, for now, you can think about it as a specific "Quiz Attempt" for example.
- Other fields: for now, the rest of xAPI fields have a basic data validation so every plugin is responsible for implementing it's own checks if they need them.
- The
About Resource Endpoint
returns metadata about the LRS (for instance, the xAPI version or LRS configuration details). - The
Activities Endpoint
returns metadata about a particular, unique activity. "Unique activities" may be, for example, different online courses, and their metadata might include their titles, descriptions, and usage instructions. - The
Agents Endpoint
returns metadata about a particular agent. An "agent" may be a learner or class cohort, for example. - Three endpoints fall under the
Document Endpoints
category; these endpoints all involve user-defined key-value pairs, which are typically unique to a given system. The Document Endpoints are primarily used by (local) Learning Activity Providers. The data stored in these endpoints represent the current situation at a given time, and those data can be updated (replacing old data) if/when the current situation changes.- The
Agent Profile Endpoint
allows the storage and return of universal data about a particular user (for instance, the learner's preferred language, accessibility preferences such as closed captioning). - The
Activity Profile
allows the storage and return of universal data about a particular activity (for instance, minimum required score, time limit, what happens if the time limit is exceeded). - The
State Endpoint
allows the storage and return of data about the current state of an activity for a particular learner (for instance, bookmark, state of play of the simulation, other state variables). In other words, the State Endpoint stores data about an activity/agent combination.
- The
The xAPI specification can be consulted in the xAPI specs page: https://github.com/adlnet/xAPI-Spec.
Moodle xAPI functionalities
The final objective of Moodle xAPI library is NOT to implement a full LRS inside Moodle but to provide an easy way to handle xAPI statements and xAPI states within any plugin that needs it.
Moodle supports the main xAPI request which is called "statement" and, from Moodle 4.2 onwards, also supports state:
- A statement must be seen as a tracking message that can be used by any plugin to store user activity directly in Moodle without programming any additional web service.
- A state should be used to store the user progressing in the play.
The current library implements:
- New webservices:
- core_xapi_statement_post to process xAPI statements and generate standard Moodle events.
- core_xapi_post_state to store a xAPI state.
- core_xapi_get_state to get an xAPI state data.
- core_xapi_delete_state to remove a xAPI state.
- A class \core_xapi\handler that any plugin can extend in order to use xAPI and generate specific plugin contexts. This way, any plugin could use xAPI without implementing any new web service.
- A class \core_xapi\iri to easily translate random information into valid IRI (Internationalized Resource Identifiers) values (needed for xAPI objects and verbs)
- A class \core_xapi\local\statement to create and extract information from statement data.
- A class \core_xapi\local\state to create and extract information from state data.
- A bunch of predefined classes in \core_xapi\local\statement\item_XXX to generate xAPI statement items from the plugins (example provided in Generating statements in PHP).