Skip to content
xAPI Bookmarklet
Use the xAPI bookmarklet prototype to capture website activities as xAPI statements.
The Experience API lets you record self-directed learning experiences, such as reading a web page.
The xAPI Bookmarklet is a simple tool that shows a little bit of that power. A bookmarklet is a simple application that runs inside of a standard internet browser bookmark. The Experience API bookmarklet lets you record any webpage that you “experience” to an LRS. The new bookmarklet has the added ability to select a different verb, rate likelihood of return visits, and assign tags to the statement.
Here are the steps to get going:
- Use the generator below to generate your own personal “xAPI Reporter” (it will just look like a link), then add the bookmarklet to your browser’s bookmarks (or bookmark toolbar). The easiest way to do this is to just drag the link to your bookmarks bar.
- After the bookmarklet has been added to your browser’s bookmarks, go to a web page, any web page, and click the “xAPI Reporter” in your bookmark menu or toolbar.
- Once the statement reporter appears, a preview of the statement is shown at the bottom of the display. You can send a simple statement or a customized statement:
- For a simple statement, simply click “Send Statement.”
- For a customized statement, complete the optional fields and click “Send Statement.”
- Visit your LRS and see the statements that have been generated.
var lib = "https://xapi.com/wp-content/assets/Bookmarklet/4.0.0/bookmarklet-min.js";
function encode64(input) {
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
output = "",
chr1, chr2, chr3,
enc1, enc2, enc3, enc4
i = 0;
chr1 = chr2 = chr3 = "";
enc1 = enc2 = enc3 = enc4 = "";
do {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) <> 4);
enc3 = ((chr2 & 15) <> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
}
else if (isNaN(chr3)) {
enc4 = 64;
}
output = output +
keyStr.charAt(enc1) +
keyStr.charAt(enc2) +
keyStr.charAt(enc3) +
keyStr.charAt(enc4);
chr1 = chr2 = chr3 = "";
enc1 = enc2 = enc3 = enc4 = "";
} while (i < input.length);
return output;
}
function generateBookmarklet() {
var user = document.getElementById('user').value,
pass = document.getElementById('pass').value,
endpoint = document.getElementById('endpoint').value,
email = document.getElementById('email').value,
name = document.getElementById('name').value,
auth;
if (isEmpty(email) || ! validateEmail(email)) {
alert("Email field is invalid.");
return;
}
if (isEmpty(name)) {
alert("Name field is invalid.");
return;
}
if (isEmpty(user) || isEmpty(pass) || isEmpty(endpoint)) {
alert("All fields are required.");
return;
}
auth = "Basic " + encode64(user + ":" + pass);
document.getElementById('bookmarklet').innerHTML = "xAPI Reporter";
document.getElementById('bookmarklet').href = generateHref(auth, endpoint, email, name);
}
function generateHref(auth, endpoint, email, name) {
return [
'javascript: function rbm(){window.rbmAuth="',
auth,
'",window.rbmEndpoint="',
endpoint,
'",window.rbmEmail="',
email,
'",window.rbmName="',
name,
'";',
'var a=document,b=a.createElement("sc"+"ript"),c=a.body,d=a.location;',
'b.setAttribute("src","',
lib,
'");c.appendChild(b)}rbm();void 0'
].join("");
}
function validateEmail(email) {
var expr = /\S+@\S+\.\S+/;
var regex = new RegExp(expr);
return email.match(regex);
}
function isEmpty(str) {
return (!str || !str.length);
}