Forum Discussion
Pass custom value to in built 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.
- Jürgen_Schoene_9 months agoCommunity Member
are you using the correct variable name and type?
- DilshanSamarawe9 months agoCommunity 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.- Jürgen_Schoene_9 months agoCommunity Member
here is a some tutorials for xAPi on youtube
https://www.youtube.com/watch?v=v-U7NUnqFZY
https://www.youtube.com/watch?v=8122oia95WI
here more infos from articulate for the includes xAPI function in storyline
https://access.articulate.com/support/article/Storyline-360-Custom-xAPI-Statements