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!
- SteveFlowersCommunity Member
You could use other sheets. Depending on the scope and access needs, the way I'd handle that is by adding a field to capture the course ID or title and use a filter to change the report display.
Google Apps Scripts are pretty fantastic. You can even automatically send formatted emails based on a variety of variables.
This is extracted from a function that gathers info from a sheet and sends emails to program owners for a departure clearance process. There is a limit to the number of emails that can be sent from each account per day. For a corporate or government account it's something like 1500.
if (emailSent =="" && emailAddress!="") { // Prevents sending duplicates
var subject = "[Exit Clearance] "+SystemName;
var messageBody="PLEASE DO NOT REPLY TO THIS MESSAGE.<br/><br/>"+MemberName+" ("+MemberOffice+") will be departing the agency after "+DepartureDate+".<br/><br/>You have been listed as program contact for <b>"+SystemName+"</b>. Please process the exit for the member listed above as necessary and click the link below to confirm. <br/><br/><a href='https://docs.google.com/a/nara.gov/forms/d/FORMID/formResponse?entry.2015203526="+uid+"&entry.2111276816="+SystemName+"&entry.2115168075="+MemberName+"&entry.439662642="+MemberOffice+"'>Confirm receipt and action.</a><br/><br/>Clicking the link confirms receipt and indicates that the system or program owner will process the required action on or after the date of departure. A reminder will be sent after the scheduled departure date.";MailApp.sendEmail(emailAddress, subject,'',{htmlBody: messageBody});
sheet.getRange(startRow + i, 3).setValue(EMAIL_SENT);
// Make sure the cell is updated right away in case the script is interrupted
SpreadsheetApp.flush();
} - SteveFlowersCommunity Member
Hi Laura -
The Jquery needs to be loaded ahead of the script fire. There is some time-lag between the creation of the object and the actual load and initialization of the library. So if you try to call something immediately, it'll probably fail. I usually try to load it on the base layer then call another layer on a delay to execute. This provides 3 to 5 seconds of lead time which seems to be enough to consistently get the library in.
If you were on a dial-up connection, this could be close.
- SteveFlowersCommunity Member
The other thing you could try is a setInterval call that looks for something jquery unique to load before firing your ajax function and canceling the interval. This is probably better than the delay as it would still work if jquery took forever to load.
Like looping to check for this every second or so:
if (typeof jQuery!='undefined') { //run your jquery ajax call and cancel the interval}
- 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
- BonnieAnderson1Community Member
Hi Kate..this is so awesome. Once it is in place, though, how will it be used? What are you doing with the Google Sheet containing these data?
- KateRobertsonCommunity Member
Hi Bonnie, in my course I ask my learners to rate their understanding against 4 statements before and after the course. The ratings are variables that get exported to a google spreadsheet so I can analyse the data and how learners feel they have developed over the course. Hope that makes sense!
- BonnieAnderson1Community Member
Perfect! This is the first valid alternative I've seen to Articulate Online for actually collecting valuable analytics. Well done!
Bonnie
- KateRobertsonCommunity Member
Thanks! I was very pleased when I got it to work because it is going to be very useful.
- JacintaPennCommunity Member
Thanks for that - I get asked for this all the time. Kate I loved your step by step instructions. Steve I loved your idea of using a javascript trigger instead of having to put something in the published folder and being able to put variables into a google form would be awesome - but I think I would need a few more step by step instructions to be able to make it work. Do you think you could explain how to do it, for say, the variable scorepercent and a variable for name? I do get asked for this all the time.
- KateRobertsonCommunity Member
Thank's Steve - I will try your javascript to automatically add the jquery line into my files.
Great example, thanks Erich!
Jacinta - you need to set up a spreadsheet where the columns are 'scorepercent' and 'name', follw the instructions above to add code to the google spreadsheet, then in the javascript you add to the articulate trigger you would put (just make sure the column titles and the variables are spelt exactly the same and in the same case):
var player = GetPlayer();
$.ajax({
url:
"Current web app URL",type: "POST",
data: {"name": player.GetVar("name")
, "scorepercent": player.GetVar("scorepercent")},
success: function(data){
alert(data);
},
error: function(err) {
console.log(err);
}});
return false;
Hope that helps!
- JacintaPennCommunity Member
Thanks so much Kate, will try it over the holidays. If I can get it to work,
I'll have a great new tracking option for all the small businesses who can't
afford LMS systems. My country is over 90% small businesses so that's a big
market.Jacinta Penn
Workbright eLearning
- MichaelBurns2Community Member
Has anyone done this with Chrome lately? The method works beautifully in Firefox, but if you try it in Chrome, it blocks the javascript elements loading on the page by default (you'll get an alert in the browser bar, with the option to load the scripts. Without doing this, none of the scripts will run).
Any way to get around this? It'd be nice and easy if we could limit everyone to one browser, but that won't happen.
- LouiseLindopCommunity Member
Thanks so much Kate. This is so good and worked first time!
- KateRobertsonCommunity Member
Glad it was useful to you Louise :)