Forum Discussion
How to access xAPI/Tin Can LMS variables in JavaScript
perhaps a variant of my first solution
function parseName( inURL ){
const urlParams = new URLSearchParams(inURL.split("?")[1]);
var name = "unknown";
if( urlParams.has("actor") ){
var actor = JSON.parse( urlParams.get("actor") )
if( "name" in actor ){
name = actor.name;
}
} else {
console.error( "no 'actor' in url: ", urlParams );
}
console.log( "name: " + name );
return name;
}
var url = window.location.href;
var name = parseName( url );
GetPlayer().SetVar("name", name);
name = actor.name; <- without [0]
- RobertWebbe-4043 years agoCommunity Member
YES, you did it! Thank you very, very much, you're my hero of the day Jürgen! 🙏😀
- RobertWebbe-4043 years agoCommunity Member
Hi Jürgen (master of javascript),
In the course I'm creating at the moment, I like to use the first name only of a learner. So I thought to add a split in the name variable but this is only working for those users who have one first name. Some of the users have multiple first (and last) names so that's not going to work because there is no logic split point.
In the meantime I found out that when I use "inspect" on the page which is running, I find this in the HTML code:
enrolment_model:{"id":3959527,"user_id":481786,"course_id":63080,"uuid":"831754a1-31a7-46da-afd9-c55486b698ec","course_admin":0,"hashtag":"","points":5,"score":5,"levels_completed":0,"leaderboard_opt_out":0,"streak_score":"0.0","latest_completed_attempt_id":849316,"created_at":"2023-06-12 09:56:35","updated_at":"2023-06-20 08:52:29","completed_at":null,"mandatory":0,"start_at":"2023-06-20 08:52:29","due_date":null,"expires_at":null,"recompletion_start_date":null,"deleted_at":null,"assigned_type":"User","assigned_id":481786,"from_external_provider":0,"requires_recalculate":0,"is_tutor":true,"has_full_game_access":true,"user":{"id":481786,"org_id":1762,"uuid":"494b54d0-9ed5-4f2d-8a98-7f0bb2dbe12b","username":"robert.webbe@vodafoneziggo.com","sso_id":null,"email":"robert.webbe@vodafoneziggo.com","fname":"Robert","lname":"Webbe","tag_line":"","summary":"","location":Do you know a way how to read the fname and lname via javascript?
Thx!