My custom javascript cannot pull the Canvas User ID while used in Canvas, but can in SCORM cloud

CindyFenske
Community Novice

Hello! 

In my Storyline project, we are hosting an artificial intelligence based tutor on an AWS server - to keep some privacy, the start of the URL is https://s3.us-east-2.amazonaws.com and the end is /index.html?user=[%UserID%]

Our goal is to have the following javascript search for the Canvas User ID, store it in the URL, and then keep track of that user's conversations with the AI tutor: 

 

 

// Get the SCORM API
function getAPI(win) {
    var API = null;
    while (win && !API && win.parent && win.parent !== win) {
        win = win.parent;
        API = win.GetPlayer ? win.GetPlayer() : null;
    }
    return API;
}

// Retrieve Canvas User ID
var API = getAPI(window);
var userID = "unknown"; // Default value

if (API && API.GetStudentID) {
    userID = API.GetStudentID();
    
    // Debugging: Show the User ID if it's retrieved
    alert("User ID Retrieved: " + userID);
} else {
    // Debugging: Show an error message if User ID is not retrieved
    alert("Error: User ID not retrieved. SCORM API might not be available.");
}

// Set the User ID in Storyline Variable
var player = GetPlayer();
player.SetVar("UserID", userID);

// Confirm that the variable has been set (optional)
alert("User ID set in Storyline: " + userID);

 

 

 

When the user clicks the red button, it runs this script and also opens the link to our AI tutor. (See screenshot 1). When we export the storyline as a SCORM package and import it into SCORM cloud, the javascript successfully searches for the UserID and tries to populate it in both the URL and the (temporary for testing) "User ID:" field in Storyline, but because it can't find it, it displays error messages. (see screenshot 2). 

However, when we upload this same file to Canvas, the url just keeps it's placeholder and does not display any error messages. 

The inspector in Chrome shows screenshot 3, but we confirmed our cross-origin frame permissions are wide-open and should not be causing any problems. 

So we're wondering if something on Canvas's end is blocking our ability to gather the user ID. I'm happy to detail the situation more, but is anyone able to help? I'm just looking for a solution that finds the user ID in Canvas and puts it into the AWS url. We have a tight turnaround on this and either hope it's a solvable issue or the issue isn't on our end. 

Thank you in advance! 

Labels (1)
0 Likes