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!
- devolinadeshmukCommunity Member
Kate Robertson- Thanks a lot for your solution. It is just awesome and explanation is too detailed and easy to follow. So much needed this solution and this post of yours came to rescue. Thanks again!
- devolinadeshmukCommunity Member
Hi Kate, how do we map the learner's with their score. I have used this method of retrieving variable value in google spreadsheet. It worked well in my computer, but how to i map the learner's with their score? I mean is there a way to get learner's name and his respective score in the google spreadsheet without using forms ?
- KateRobertson-8Community Member
Hi Dev, if the score is a variable then you can add that in. Likewise, make the name a variable.
- StephenGoreyCommunity Member
old?
- MaximeCRUZEL-e0Community Member
Hello, is this script still working?
For the moment, my tests with main post's content and that of the video sent by Lizzie Angell are not concluded ...
- MaximeCRUZEL-e0Community Member
UPADATE : I tried this : https://community.articulate.com/discussions/articulate-storyline/articulate-storyline-export-to-google-drive
It functioned.
- GerhardFenkartCommunity Member
Kate Robertson - you are quite the genius! Thanks so much for this helpful code.
- ResidentialCommCommunity Member
Hello Kate,
I am trying to get the record of the learner's record exported from the storyline 360 courses to google sheet for backend record tracking. I have created the demo version, where I have created a few slides, the first slide to collect the student's record using 'text entry.' On the second slide, I have made a demo quiz question, the third slide is the result slide, and on the last slide, I have used the variables to get the student's record on the slide and set up the javascript to export the data using the option "When the timeline starts on this slide."
I have set up the google sheet as per the instruction on this article and set up the javascript variables on my Storyline 360 course. But somehow, the data is not pushed from the storyline to the google sheet. Also, I want to capture "Results2.ScorePercent" on the google sheet to check the score of the students.
Here is my google sheet script code as per this article:
// 1. Enter sheet name where data is to be written below
var SHEET_NAME = "DATA";
// 2. Run > setup
//
// 3. 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)
//
// 4. Copy the 'Current web app URL' and post this in your form/script action
//
// 5. Insert column names on your destination sheet matching the parameter names of the data you are passing in (exactly matching case)
var SCRIPT_PROP = PropertiesService.getScriptProperties(); // new property service
// If you don't want to expose either GET or POST methods you can comment out the appropriate function
function doGet(e){
return handleResponse(e);
}
function doPost(e){
return handleResponse(e);
}
function handleResponse(e) {
// shortly after my original solution Google announced the LockService[1]
// this prevents concurrent access overwritting data
// [1] http://googleappsdeveloper.blogspot.co.uk/2011/10/concurrency-and-google-apps-script.html
// we want a public lock, one that locks for all invocations
var lock = LockService.getPublicLock();
lock.waitLock(30000); // wait 30 seconds before conceding defeat.
try {
// next set where we write the data - you could write to multiple/alternate destinations
var doc = SpreadsheetApp.openById(SCRIPT_PROP.getProperty("12msX31fJ5bqw2ajJk4oJxPjFkSs5x-Rbot2PspwuTEs"));
var sheet = doc.getSheetByName(SHEET_NAME);
// we'll assume header is in row 1 but you can override with header_row in GET/POST data
var headRow = e.parameter.header_row || 1;
var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0];
var nextRow = sheet.getLastRow()+1; // get next row
var row = [];
// loop through the header columns
for (i in headers){
if (headers[i] == "Timestamp"){ // special case if you include a 'Timestamp' column
row.push(new Date());
} else { // else use header name to get data
row.push(e.parameter[headers[i]]);
}
}
// more efficient to set values as [][] array than individually
sheet.getRange(nextRow, 1, 1, row.length).setValues([row]);
// return json success results
return ContentService
.createTextOutput(JSON.stringify({"result":"success", "row": nextRow}))
.setMimeType(ContentService.MimeType.JSON);
} catch(e){
// if error return this
return ContentService
.createTextOutput(JSON.stringify({"result":"error", "error": e}))
.setMimeType(ContentService.MimeType.JSON);
} finally { //release lock
lock.releaseLock();
}
}
function setup() {
var doc = SpreadsheetApp.getActiveSpreadsheet();
SCRIPT_PROP.setProperty("12msX31fJ5bqw2ajJk4oJxPjFkSs5x-Rbot2PspwuTEs", doc.getId());
}Here are the variables I have used to collect the data:
Name
LastName
SBUID
Here is the javascript-based on this article:
var player = GetPlayer();
$.ajax({
url:
"https://script.google.com/macros/s/AKfycby-NIv6hl6a71GnO8jF9wC-Ac5jq0os3y1PjD0rWzzNjHY1NgQ/exec",type: "POST",
data: {"Name": player.GetVar("Name")
, "LastName": player.GetVar("LastName")
, "SBUID": player.GetVar("SBUID")},
success: function(data){
console.log(data);
},
error: function(err) {
console.log('Error:', err);
}});
return false;
Can someone help me to find the problem of why this thing is not working? I also want to populate the student's percentage/score received in the quiz using the inbuilt variable. Is there any changes/update has been done on google's side or Articulate side, and that is why codes are not responding?
Thank you,
Pratik Parekh
- YaachYaachCommunity Member
Hi Kate Robertson, the link to the script to be inserted on Google Editor is not working. Could you please update the link or paste the code. Thanks
- MariaCSStaff
Hi, Yaach.
Since this is an older discussion, Kate might not be subscribed, but you're welcome to contact them directly through their profile by clicking on their name and selecting Contact Me.