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!
- ErichRenkenCommunity Member
Hi, Paul. I've played around with that a bit and had success using the Google "Query Language"
https://developers.google.com/chart/interactive/docs/querylanguage#Setting_the_Query_from_JavaScript
What makes this tricky is that you'll need a unique way of identifying the person taking the course, assuming that there will be multiple rows in your spreadsheet. Otherwise, you might pull back a different person's data.In this way, Google Sheets start functioning like a database in which you can set/get/edit/delete values.
- PaulMacDonell-bCommunity Member
Erich,
Thanks for this! Good material for my subway rides. My son, a mobile
developer, is also very excited to see how this works.
- LouiseLindopCommunity Member
Thanks so much Kate. This is so good and worked first time!
- KateRobertsonCommunity Member
Glad it was useful to you Louise :)
Glad that this is still assisting people Louise :)
- YoniHCommunity Member
Thanks to everyone who has helped make this a reality, love this community!
Please help, I have attempted Steve's approach but I can't get the variables to go to google. Does the google form need to have a specific security setting (like share with everyone)? I am using chrome with the deployed on a web server.
Any help would be tremendously appreciated!
Hi Yoni,
I'm not familiar with the specifics of Steve's solution, but I suspect the doc will need to allow sharing and edits by anyone with the link - as that's how it'll be communicated from Storyline.
Steve is still a regular contributor here in the forums so hopefully he'll pop back in and share some additional information here.
- SteveFlowersCommunity Member
The Google Form itself should be shared with everyone.
However, there are a few things that can stop up the works. Watching the Javascript console is helpful in tracking down where things might be wrong. Here are a list of potential gotchas:
- The JQuery dependency isn't loaded before the ajax call. This means on the same slide on the base layer with your ajax call in another layer or in another slide that's sure to be hit. Loading everything at once, it'll likely fail as there's quite a bit that happens to force the load.
- There's another script error somewhere. Invalid script, a missing variable, an LMS call tested outside of an LMS. Lots of stuff can put a stop to script execution before you reach the ajax call.
- Using the wrong form address. In my example above, the link provided was for my organization. It includes the org address. If you use this same string, it'll fail unless your part of my org:)
fTarget="https://docs.google.com/a/nara.gov/forms/d/YOURFORMID/formResponse";
Thanks Steve - I knew you were out there somewhere. ;-)
- LouiseLindopCommunity Member
Thanks to everyone for input on this subject. I have the export to the google spreadsheet all working nicely however after it is written out I get a message back from the stating [object Object] - has anyone else come across this?
- YoniHCommunity Member
Ashley & Steve - Thank you both. I was having issues with the permissions on the spreadsheet.
- KateRobertsonCommunity Member
I am glad this is still helping people :)