Referral Tracking in xAPI

I have recently been experimenting with xAPI (also known as the TinCan API), which is a new way to track experiences through eLearning.

xAPI can track many things (see the full list of “verbs” here) in the pattern of someone – did something – to something. For example, Lizzie – accessed – this resource. Great, but how can we track where I accessed it from?

Knowing where a learner came from to get to your resource is valuable so that you can filter the statements in your LRS to be able to see just the students that you are interested in, for example; just the ones who came from a certain DLE course. After (an admittedly brief!) Google search to see whether anyone has already made xAPI track the referrer, I decided to write it myself. And with a tiny bit of PHP knowledge, it’s easy!

The PHP code:

The explanation:

(I’m not going to explain the entire statement, check out the “deep dive” series for a much better explanation of how each part works; I’m just going to explain the bits I’ve added to track the referral.)

The first important part here is the verb – “accessed”.

There are two parts to setting up the “Accessed” verb:

  1. We set the verb id using the tincan URI’s defined in the Registry
  2. We then add a display name, so we can easily read the statement in plain English.


The next important part to set up is the Context. Context’s apparently aren’t that widely using in statements yet, but they can add help to convey further meaning and seemed to me to be the most logical place to put the referrer. There are nine optional properties a context can have, and the one I have chosen for my referrer is “platform” – so my statement can read “Lizzie accessed this resource from that platform” .

There are two parts to this context I have created:

  1. Set the platform property
  2. Use the built in PHP variable “HTTP_REFERER” to get where they have come from
    (Please be aware that this is for demonstration/testing purposes only – according to the PHP docs, HTTP_REFERER “cannot really be trusted” and so in your production code you’ll probably want to use URL query strings or something else more reliable to get your referrers, particularly if you own the pages they will be coming from.)

It might also be helpful to add in a timestamp to this statement so you know when your learner accessed the resource, the TinCanPHP library I am using adds this for me.

Leave a Reply

Your email address will not be published. Required fields are marked *