Forum Discussion

DilshanSamarawe's avatar
DilshanSamarawe
Community Member
6 months ago

Pass custom value to in built xApi statements

Hi,

I am currently working on passing custom values to articulate xApi-published content. I want to pass a custom value (ex: courseId = 15) to in-built xApi statements when actors interact with content. I was able to pass a custom parameter with the launch URL according to this article, Configure Launch URL
So I added a custom parameter like below and thought that value would be added to the generated xApi statements.

http://my.lms.com/TCActivityProvider/index_lms.html

?endpoint=http%3A%2F%2Fmy.lms.com%2Flrs%2Fendpoint%2F

&auth=Basic OjFjMGY4NTYxNzUwOGI4YWY0NjFkNzU5MWUxMzE1ZGQ1

&actor=%7B%22name%22%3A%20%5B%22First%20Last%22%5D%2C%20%22mbox
%22%3A%20%5B%22mailto%3Afirstlast%40mycompany.com%22%5D%7D
&courseId=15

But when I checked the xApi statements in LRS, there wasn't anything related to my custom parameters.
So I want to know if there is anything I am missing or what I am doing wrong. How can I set custom values to store in the built-in XAPI statements?

  • Hi Phil,

    Yes, I am currently using the 'Execute JavaScript' trigger to get value from URL.

    // Function to get parameter from URL
    function getParameterByName(name, url) {
        if (!url) url = window.location.href;
        name = name.replace(/[\[\]]/g, "\\$&");
        var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
            results = regex.exec(url);
        if (!results) return null;
        if (!results[2]) return '';
        return decodeURIComponent(results[2].replace(/\+/g, " "));
    }

    // Retrieve courseId parameter from the URL
    var courseId = getParameterByName('courseId');

    // Set the courseId value to a Storyline variable
    var player = GetPlayer();

    player.SetVar("CourseID", courseId);

    var courseIDFromVariable = player.GetVar("CourseID");

    alert("Course ID: " + courseId);
    alert("Course ID from variable: " + courseIDFromVariable);


    Using the above code, I was able to successfully capture the courseId from the URL. However, I encountered another issue when trying to set the articulate variable, which is that it is always returning null, even when I use a hardcoded value like this.
    player.SetVar("CourseID", 15);
    player.GetVar("CourseID"); this always returned a null value.

    This is where I am currently stuck. I don't even know if this is the right way. I would like to know if I am able to fix the setting variable, Can I only set this value to custom xApi statements, not to the in-built xApi statements? Sorry for any confusion; I am very new to the articulate. Any help would be much appreciated.

      • DilshanSamarawe's avatar
        DilshanSamarawe
        Community Member

        Omg, Thank you so much for your help. I didn't know I had to manually add variables through articulate. I thought the SetVar() method would create a new variable for me. Adding the variable to my project resolved the null value issue.
        Also, do you know how I can set this variable for in-built xApi statements? I know we can set variables for custom xApi statements. Any advice would be much appreciated. Thank you again.

  • Hi, 

    Thanks for taking your time to help me with this. As for the tutorials you suggested, yes, I reviewed all of them and was able to send a custom xApi statement by setting my custom variable, which I got from the URL.


    Also, this custom xApi statement was stored in LRS without any issues.

     

    As you can see, the value of my variable is stored as "CourseID_112996" in the Interacted xApi Statement. My concern is how I can set this variable to Articulated-generated xApi statements. For example, both "Jimmy experienced Intro" and "Jimmy attempted MathGame" are created within the articulate tool. Not by me. Basically, I am creating a course in an LMS. Articulate content is only a part of that course. Therefore, I like to store my course ID in xApi statements when users interact with the course. As for the custom Xapi statements, I am able to store my course ID like your tutorials suggested. But I also want to set courseId to in-built xApi statements as well, so I can query the user progress with courseId. That's what I am trying to achieve. With your help, I was able to add custom variables to my custom xApi statements. But my main concern is how I can set my variable to xApi statements created with articulate.