Forum Discussion
Exporting Variables into a Google Spreadsheet
Heya Kate -
I've used the method you show here as well and it works pretty well to setup a Google Spreadsheet as an endpoint. This method is handy for capturing inline survey results, to grab choices for choice analysis, and for double capturing completions if your LMS happens to be temperamental. One of the cool things about the Google Spreadsheet is the notification / subscription feature. Subscribing to updates on a per-addition or digest basis is great for infrequent submissions. It's also handy to use formulas and linked sheets to create public dashboards. The original data can be locked away while the linked data (filtered and sanitized) can be exposed in a published location.
Here's an alternate method that uses a Google Form as the intermediary to submit the fields from Storyline. A little less setup using a form to process the submissions and I've had fewer issues with permissions (if your Google Apps instance is corporate or government, using GAPPS script is potentially problematic).
Add this to a trigger when the slide loads. This will write the JQuery library to your header so you won't need to do any post-publish surgery. This will load Jquery for both the HTML and HTML5 versions. This can also be used for other libraries. I've successfully used this method to load up the soundmanager.js library for persistent background music.
function add_script(scriptURL,oID) {
var scriptEl = document.createElement("script");
var head=document.getElementsByTagName('head')[0];
scriptEl.type = "text/javascript";
scriptEl.src = scriptURL;
scriptEl.id=oID;
head.appendChild(scriptEl);}
//only want to add these once!
if(document.getElementById('jquery')==null){
add_script("https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js","jquery");
}
After you've built your form and viewed the live form, inspect the form elements or explore the source to find the field references for your form. These will be something like entry.156531987. Write these down or copy them into another reference document. While you're at it, grab the form ID from the URL.
var player=GetPlayer();
var vRate=player.GetVar("slider1");
var vSuggestion=player.GetVar("TextEntry");
var fTarget="https://docs.google.com/a/nara.gov/forms/d/YOURFORMID/formResponse";
function submit_form(){$.ajax({
url: fTarget,
type: "POST",
data: {"entry.156531987" :vRate,"entry.1547132205":vSuggestion},
success: function(data) {
//won't return anything since it's cross domain
}
});
return false;
}
setTimeout(submit_form(), 2000);
Edit: Left off a little bit. I delay the submission of data for a couple of seconds for some reason. Must have fixed an issue in testing. Probably will work find without the delay.
- BonnieAnderson110 years agoCommunity Member
Thanks Steve!
Bonnie
- PaulMacDonell-b10 years agoCommunity Member
Steve,
This is wonderful code. I've used this technique and it works for one of my columns of data. I'm sure I'll figure it why the other columns are not saved eventually.
My main questions though is "How do I load the variables I've saved to the Google Spreadsheet back into Storyline?" I want to do this in order to save the progress of videos that a user has viewed in Storyline. There are three videos and I'd like to record which ones they have watched. I mark these with a checkmark in the story. Your routine allows me to do this.
If the user leaves before watching all three videos, the variables in the Google spreadsheet will track that. When they return to the story, I'd like them to know which videos they have watched and which ones they haven't, again, by checking (using states) those that they've watched. The data from the Google spreadsheet, once loaded, will provide this capability.
Of course, I'm a script kiddie with little knowledge of JavaScript. Any help you can provide will be most appreciated! Thanks again for your contributions!!!
- LauraBrunning10 years agoCommunity Member
Hi,
We're using the form solution to send variables to a Google sheet. All works OK, but only if I edit the story.html file and add in the <script type="text/javascript src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> bit in the header.
I've tried the solution above to automatically write it to the header and added it to a trigger before the rest of the javascript stuff kicks in, but this way, it doesn't send the data to the Google sheet. It'll only work if I add it manually to the output file before zipping.
Am I missing something really obvious? Any help would be most appreciated!