The short version
There are a lot of possible ways to build an xAPI statement, with a LOT of potential information you could include. This flexibility is valuable if you have complex data you need to track. But sometimes, maybe even most of the time, all you need is something simple.
All an xAPI statement truly requires is an Actor, a Verb and an Object (which the TinCan API refers to as a "target"). The SendSessionEvent function will add the Actor information (i.e. the logged in user) to the passed eventStatement, so all you need to provide is a verb and an object, and their associated IDs.
The following code demonstrates how to do this:
TinCan.Statement eventStatement = new TinCan.Statement();
eventStatement.verb = new TinCan.Verb();
eventStatement.verb.id = new Uri("https://pixovr.com/xapi/verbs/exampleVerb");
//the target is equivalent to the object in the xAPI specificiation
TinCan.Activity eventActivity = new TinCan.Activity();
eventActivity.id = "https://pixovr.com/xapi/exampleProject/objects/exampleObject";
eventStatement.target = eventActivity;
ApexSystem.SendSessionEvent(eventStatement);
There are a few things to note:
- The TinCan API calls objects "targets". This is a convention to prevent conflicts with the object keyword. Any data you add to the eventStatement.target property will show up as an "Object" property in Apex.
- Objects (targets) can be one of several types, but "Activity" is by far the most common type. Refer to the official xAPI spec for more information about the other types.
- The verb.id needs to be an URI object, but the eventActivity.id only needs to be a string.
Example Report
If you were to use the above code in your project, the data as seen on Apex would look something like this:
id: edb38f92-d9df-4781-8071-ff2c65c228fe
actor: {
"mbox":"[email protected]",
"objectType":"Agent"
}
verb: {
"id":"https://pixovr.com/xapi/verbs/exampleVerb"
}
object: {
"id":"https://pixovr.com/xapi/exampleProject/objects/exampleObject",
"objectType":"Activity"
}
context: {
"platform":"OSXEditor",
"revision":"1.00.00",
"registration":"22112aa8-e5ee-41b9-8403-77eafb0b3229"
}
version: 1.0.3
timestamp: 2022-07-18T23:36:59.9719600Z
Notice that the actor, context, version and timestamp properties were all automatically created for you. Of these properties, context is the only property you could potentially add additional data to, and more information on that is found in The Longer Version