Sending data to Storyline?

I need to send data to a Storyline course from our website. What's the best way to do that?  Currently I'm setting a cookie in my server-side code then reading that in a JavaScript file I include in story.html.  I'm doing something like the below but I'm wondering if there's an easier way I'm missing.

function readCookie(name) {

  var nameEQ = name + "=";

  var cookieArray = document.cookie.split(';');

  for (var i = 0; i < cookieArray.length; i++) {

    var cookie = cookieArray[i].replace(/^\s+/, '');

    if (cookie.indexOf(nameEQ) == 0) {

      return cookie.substring(nameEQ.length, cookie.length);

    }

  }

  return null;

}

var documentLoadedTest = setInterval(function() {

    if (document.readyState === "complete") {

      var player = GetPlayer();

      if (player.SetVar) { 

      var inputData = readCookie("InputData");

      player.SetVar("InputData", inputData);

      clearInterval(documentLoadedTest);

    }

 }

}, 10);

3 Replies
Ramon Smitherman

I am trying to do the same.  JavaScript is extremely weak when it comes to reading a single cookie.  A call to cookies returns the entire collection which you have to parse.  Much as you have in your example above.

Not being strong in JavaScript I am attempting to us a function much like you have.

Can you help me understand how your script is working?

What cookie is set already from your application?

What variable in Storyline are you storing that parsed cookie value?