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!
- KateRobertsonCommunity Member
Hi Jason, one thing I've noticed - your sheet name needs to be called 'DATA' - you seem to have two sheets, which one are you trying to write to? I would need to see the code you put into google to see if there are any other problems. Kate
- JasonNagelsCommunity Member
Hi Kate -
The sheet that wasn't called DATA (called form responses), was created just a couple of minutes ago when I tried creating a form based on the spreadsheet. I have deleted that sheet now.
The sheet I was using originally was the DATA tab.
- KateRobertsonCommunity Member
Also, I think you need to make your google spreadsheet editable by anyone - at the moment it is set to anyone with the link can view but that means that articulate can't edit it - if that makes sense?!
- JasonNagelsCommunity Member
Thanks Kate. I didn't notice that.
I just modified the permissions so anyone can access and edit the sheet.
I just tried it and it didn't work. Now I'm starting to thing it may have to do with the Script function not found: doGet I get when I run the WebApp URL:
https://script.google.com/macros/s/AKfycbz7Xe_atONE7a8RSxj8UVZU5qqkEvLRdNZnGL8FXeFk_PJYPoo/exec
What should happen when I launch the webapp URL if it was working properly?
- JasonNagelsCommunity Member
another quick question - the first time I open the script editor there is a default entry of:
function myFunction() {
}
I assumed I pasted the script you provided between the { and }
is that correct?
- SteveFlowersCommunity Member
I've stopped using scripts for Google Spreadsheet data and always close off my sheets to the public unless I need Storyline to access the data.
Using Google Forms and a bit of ajax to submit the data to the spreadsheet has worked consistently for me without the need to manage a script for submission capture. You might want to give that a try. Eases the permission complications as well.
- RobertKankelborCommunity Member
Steve,
Do you have an example of how you do that?
Thanks!
- JasonNagelsCommunity Member
Hi Steve -
Is the method you describe the one covered in this forum post https://community.articulate.com/discussions/articulate-storyline/exporting-variables-to-be-read-in-a-google-docs-spreadsheet
- SteveFlowersCommunity Member
The info is there. Much of it in this doc:
https://articulate-heroes.s3.amazonaws.com/uploads/attachment/attachment_url/4238/page.pdf?dl=true
The one bit I see that's potentially missing is getting the field ID's. There's an easy way to do that by generating a prefilled link from the Google Forms editor.
- SteveFlowersCommunity Member
Sure. It's something I do pretty regularly. I'll replicate one I did a few weeks ago and post the example. It's super easy.
Form > Spreadsheet + a little javascript in a storyline trigger.
- RobertKankelborCommunity Member
This is great!...thanks for the article link, too. I look forward to the post.
- KateRobertsonCommunity Member
Jason, I have tried briefly to make your spreadsheet work but I can't see the problem. The best I can suggest is to start again. The first time you open the script editor, just delete everything that is there and paste the new script. Good luck.