Extensions are a way to include additional information in a particular xAPI object that is not part of the standard properties of that object.
For Example:
- If your module had a difficulty setting, you could track which setting a user had chosen in a context extension.
- In a javelin throwing simulation, you might would want to track both distance thrown as well as an assigned point score. "Score" is already available in the result object, and you could track the distance thrown in a result extension.
Actor, Context, Object, and Result objects can all support extensions. Regardless of which object type you are adding them to, they are handled in the same way.
First, create a new Extension object:
FXAPIExtension SampleExtension;
Then you can either use the add() or addSimple() functions to add as many key/value pairs to the Extension object as you want. These non-type specific functions require a TSharedPtr<FJsonValue>.
-
Add() — the Add() enforces the requirement that an extension key be an IRI and allows you to use an FString as your key
- AddCustom() — the AddCustom() function requires the key to be an IRI, which conforms to the xAPI spec
There are also type specific functions for adding, both with a Add and AddCustom version. Any function with AddCustom in the name requires the key to be an IRI.
-
AddString() and AddCustomString() — the value must be an FString
-
AddNumber() and AddCustomNumber() — the value must be an int
-
AddBoolean() and AddCustomBoolean() — the value must be an bool
Example Code
FXAPIExtension SampleExtension;
SampleExtension.AddCustomString("https://www.pixovr.com/xapi/extensions/iri_extension","value");
SampleExtension.AddString("simple_key", "value");
Previous Article: SendSessionEvent() Function