Forum Discussion
Exporting Variables into a Google Spreadsheet
Having read this post on how to export variables to be read in a google spreadsheet, I set about trying to get this working in my project, I soon ran into problems, I just could not get it to work as google have changed some of the ways they work their drive documents.
So, after a LOT of google searching and testing various methods, plus reading this article, I came up with the following method which is a combination of the two articles – and it works, hurrah!
1. Create a new google spreadsheet and change the sheet name (lower left hand corner) to DATA. Make sure your column names are the same as the variables you want to export (exactly matching case)
2. Find out your spreadsheet ‘key’ by looking in the address bar, the key is the long series of letters and numbers after /d/ and before /edit:
Eg: https://docs.google.com/spreadsheets/d/1gF0QCNA1TZCNY3qr2zNpWKQ8r43D39o-nqz56c7cQUs/edit#gid=1283040575
Key = 1gF0QCNA1TZCNY3qr2zNpWKQ8r43D39o-nqz56c7cQUs
3. Open the script editor (Tools ==> Script Editor) in your spreadsheet and paste the script from the attached file (I have copied and pasted this script and just kept in all the instructions)
4. There are two places in the script where it says “KEY” – copy and paste your key into these two places, between the “”.
5. Run the setUp script twice (Run menu). The first time it will ask for permission to run (grant it), then the second time you select to run it you won't get any popup indication it has run.
6. Go to Publish > Deploy as web app, enter Project Version name and click 'Save New Version', set security level and enable service (most likely execute as 'me' and access 'anyone, even anonymously).
7. Copy the 'Current web app URL' and paste in a notepad file to keep safe.
8. In Articulate, add a trigger to run javascript and use the following code, replacing “Current web app URL” with your URL you copied in the previous step (in””):
var player = GetPlayer();
$.ajax({
url:
"Current web app URL",
type: "POST",
data: {"Name": player.GetVar("Name")
, "Rating1": player.GetVar("Rating1")
, "Rating2": player.GetVar("Rating2")
, "Rating3": player.GetVar("Rating3")
, "Rating4": player.GetVar("Rating4")
, "postRating1": player.GetVar("postRating1")
, "postRating2": player.GetVar("postRating2")
, "postRating3": player.GetVar("postRating3")
, "Postrating4": player.GetVar("Postrating4")},
success: function(data)
{
console.log(data);
},
error: function(err) {
console.log('Error:', err);
}
});
return false;
9. Publish your articulate project – you need to host it somewhere like SCORM cloud or a LMS. When it has finished publishing click to open the files and edit the story.html and story_html5.html files – add the following line in under the line <!-- version: X.X.XXX.XXX --> or somewhere after <head>:
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
10. Go back to articulate and click ‘zip’ – then publish your zip file and hopefully it will work!
This isn’t for the faint hearted but it is so worth it if you can get it working! Good luck!
160 Replies
- AlisonGretchenSCommunity Member
@ Ken. I tried following all the instructions and still struggled.
I came across this website
It has a built in template that can be used for your projects. I haven't had any problems but anything can happen.
Hope this helps.
- kristianchar230Community Member
@Steve, you're a genius. How did you ever figure out the form entry ID thing? That's brilliant.
- SteveFlowersCommunity Member
If you don't want to use the iFrame method, you can use Jquery pretty easily. I don't like to do post publish surgery so I use a bit of Javascript to jack jquery into the head of the document at runtime. Note that you need to load this well ahead of your AJAX calls. Don't try to load this and your AJAX call in the same trigger.
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");
}In a separate trigger (give it some time after your JQUERY head load):
var player=GetPlayer();
var vStudent=player.GetVar("studentName");
var vSupervisor=player.GetVar("supervisorName");
var vFacility=player.GetVar("facilityName");var fTarget="https://docs.google.com/a/nara.gov/forms/d/YOURUNIQUEFORMID/formResponse";
function submit_form(){
$.ajax({
url: fTarget,
type: "GET",
data: {"entry.1481580269" :vStudent,"entry.1244291729":vSupervisor,"entry.2088465962":vFacility},success: function(data) {
//won't return since it's cross domain
}});
return false;}
setTimeout(submit_form(), 2000);- -ba470100-eae7-Community Member
Hello everyone!
I am very grateful to you for this solution and detailed explanations. Having carefully delved into it, I was able to configure the export of variables to a Google table via a Google form.There are a couple of nuances that I changed:
1. in the blockif(document.getElementById('jquery')==null){ add_script("https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js","jquery"); }replaced the link with a more recent version
https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.jsit turned out like this:
if(document.getElementById('jquery')==null){ add_script("https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js","jquery"); }2. in the block
var fTarget="https://docs.google.com/a/nara.gov/forms/d/YOURUNIQUEFORMID/formResponse";i changed the type of link:
https://docs.google.com/forms/d/e/YOURUNIQUEFORMID/formResponse";
- SteveFlowersCommunity Member
(2/2) There are a couple of ways to run submission. The first is pretty simple and doesn't require JQuery. This creates an invisible iframe and submits using that iFrame. This works pretty consistently for me. Since we aren't looking for any return to the AJAX call, this is probably lighter weight than the JQuery version.
var player=GetPlayer();
var questionID = player.GetVar("team");
var choice =player.GetVar("choice");
var questionID=player.GetVar("qRef");
var category=player.GetVar("category");
var formEvent=player.GetVar("formEvent"); //I put the URL listed under step 3 in the first part of this post into a Storyline variable.
var region=player.GetVar("region");
var role=player.GetVar("role");var goURL=formEvent+"?entry.439953588="+username+"&entry.1756523096="+category+"&entry.1042712636="+questionID+"&entry.769939824="+choice+"&entry.771181539="+region+"&entry.818358780="+role;
if(document.getElementById('sendGoogle')){
var elem = document.getElementById("sendGoogle");
elem.parentElement.removeChild(elem);
}ifrm = document.createElement("IFRAME");
ifrm.setAttribute("src", goURL);
ifrm.id="sendGoogle";
ifrm.style.visibility = "hidden";
document.body.appendChild(ifrm); - SteveFlowersCommunity Member
Hey, all -
(1/2) I've stopped using the script method awhile ago. The less complicated way to tackle this uses a Google Form paired with a Google Spreadsheet.
- Create a Google Form. Pair it with a Spreadsheet.
- Use the prefilled form option in Google Forms to grab your name/value pair variable names. You'll get something that looks like this. I add the names I want to reference into the fields before submitting.
https://docs.google.com/forms/d/e/1FAIpQLSeL2Z8hvyxK_EipeC7Fc8NDncE3VtVsMMsQZIOkCfkOPSLKgQ/viewform?entry.1518353193=NAMEFIELD&entry.1403774106=COLORFIELD&entry.1433875917=NUMBERFIELD - You'll set your AJAX function to target the form response address. It's the same address as your form except it ends with formResponse instead of viewForm. https://docs.google.com/forms/d/e/1FAIpQLSeL2Z8hvyxK_EipeC7Fc8NDncE3VtVsMMsQZIOkCfkOPSLKgQ/formResponse
- KenRussomCommunity Member
Steve Flowers Do you have any suggestions?
- KenRussomCommunity Member
Thanks to Kate for all the work, but I wish someone would create a template and instructions that exports data to google sheets or ??.
- CarrieBoothCommunity Member
Hi All,
I have had this script up and rolling and now, poof! Can't make it work!
I even tried a brand new course and it is not working! Any one else having this problem?
cdb
- KenRussomCommunity Member
WordPress site is HTTP:// and it's hosted on go-daddy. So do I needed to move to https? Nothing showing in spreadsheet. I pretty sure spreadsheet is not the problem. I can test it in google sheets and adds new rows, or course with 'undefined' because there's no data.
I followed the example that Kate's so graciously shared
- SteveFlowersCommunity Member
Hmm.. Looks like you're using a script method. Are you attempting to return data from the script? If submitting data using a standard form, you'll always get an error like this.
In your Wordpress launch, are you using http:// or https://? Appears in your error that the launch is coming from http://. Can't mix the two or it will throw an error.
Related Content
- 12 months ago
- 12 months ago
- 12 months ago
- 12 months ago