Forum Discussion
Exporting Storyline variables to Google Sheets
Hello everyone, I have no programming background and would appreciate some help.
I am trying to export variables from Storyline to a Google Sheet. The course is published on the reach 360 platform.
I used the following code for the ExcuteJavascript trigger:
console.log("JavaScript from Trigger is running!");
var player = GetPlayer();
$(document).ready(function() {
$.ajax({
url: "https://script.google.com/macros/s/.../exec",
type: "POST",
dataType: "json",
contentType: "application/json",
data: JSON.stringify({
"FullName": player.GetVar("FullName"),
"Quiz1.ScorePercent": player.GetVar("Quiz1.ScorePercent"),
"Quiz2.ScorePercent": player.GetVar("Quiz2.ScorePercent"),
"Quiz3.ScorePercent": player.GetVar("Quiz3.ScorePercent"),
"Quiz4.ScorePercent": player.GetVar("Quiz4.ScorePercent"),
"Quiz5.ScorePercent": player.GetVar("Quiz5.ScorePercent"),
"Quiz6.ScorePercent": player.GetVar("Quiz6.ScorePercent"),
"Quiz7.ScorePercent": player.GetVar("Quiz7.ScorePercent"),
"Quiz8.ScorePercent": player.GetVar("Quiz8.ScorePercent"),
"Quiz9.ScorePercent": player.GetVar("Quiz9.ScorePercent"),
"Quiz10.ScorePercent": player.GetVar("Quiz10.ScorePercent"),
"Quiz11.ScorePercent": player.GetVar("Quiz11.ScorePercent"),
"Quiz12.ScorePercent": player.GetVar("Quiz12.ScorePercent")
}),
success: function(data) {
console.log("Data sent successfully:", data);
},
error: function(error) {
console.error("Error sending data:", error);
}
});
});
return false;
I receive the following response in the console:
Javascript from Trigger is running!
and immediately after that the error: actionator::exeJavaScript - $ is not defined
I read the thread: https://community.articulate.com/discussions/articulate-storyline/exporting-variables-into-a-google-spreadsheet
But because the course is published on the reach 360 platform, I have no idea how to get to the files: story.html and story_html5.html to add the missing JQUERY library as explained in the thread in the link.
I would appreciate any help. What can I do?
5 Replies
- SamHillSuper Hero
Hi lemidadigital rather than using jQuery which is redundant in this instance, you can use native JS to complete the same function:
console.log("JavaScript from Trigger is running!"); var player = GetPlayer(); document.addEventListener("DOMContentLoaded", function () { fetch("https://script.google.com/macros/s/.../exec", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ "FullName": player.GetVar("FullName"), "Quiz1.ScorePercent": player.GetVar("Quiz1.ScorePercent"), "Quiz2.ScorePercent": player.GetVar("Quiz2.ScorePercent"), "Quiz3.ScorePercent": player.GetVar("Quiz3.ScorePercent"), "Quiz4.ScorePercent": player.GetVar("Quiz4.ScorePercent"), "Quiz5.ScorePercent": player.GetVar("Quiz5.ScorePercent"), "Quiz6.ScorePercent": player.GetVar("Quiz6.ScorePercent"), "Quiz7.ScorePercent": player.GetVar("Quiz7.ScorePercent"), "Quiz8.ScorePercent": player.GetVar("Quiz8.ScorePercent"), "Quiz9.ScorePercent": player.GetVar("Quiz9.ScorePercent"), "Quiz10.ScorePercent": player.GetVar("Quiz10.ScorePercent"), "Quiz11.ScorePercent": player.GetVar("Quiz11.ScorePercent"), "Quiz12.ScorePercent": player.GetVar("Quiz12.ScorePercent") }) }) .then(response => response.json()) .then(data => { console.log("Data sent successfully:", data); }) .catch(error => { console.error("Error sending data:", error); }); }); return false;
FYI: I haven't checked your script, but have just converted to use native JS so you do not need to load in any external JS libraries like JS, which is where the "$" related error is stemming from.
- lemidadigitalCommunity Member
Thank you!
I will try this and update here with the results.
- lemidadigitalCommunity Member
I tried, and now I don't get the error: exeJavaScript - $ is not defined. But the data doesn't reach the Google data sheet. The message: 'Error sending data' is also not received.
Does anyone have a solution?
- SamHillSuper Hero
Hi lemidadigital did you complete all of the required configuration steps for your Google Sheet? The Google Sheet needs to be set-up so that it accepts data using the API.
If you have not completed any of those steps, I would suggest you jump on ChatGPT or similar and request the "steps to post data to a google sheet using JavaScript"
- lemidadigitalCommunity Member
Finally I realized that instead of looking for a solution, I should look for a good AI tool.
I found WINDSURF and it made me scripts for Storyline and for GOOGLE APPS SCRIPT.
Now everything works great. Does anyone need me to upload the scripts?