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!

138 Replies
Albert Nardone

Hello all, I am attempting to populate a google spreadsheet with variables from my storyline 2 course and I can't seem to get it working.

I know being that vague won't get me much help but i've followed kate's steps exactly.

I am publishing the course on my web server and editing the files there to include the script src url. Perhaps my issue is with naming the spreadsheet columns as ive done that by assigning a named range, not sure if correct. If anyone could help me in more detail that would be amazing. Thanks!

Louise Lindop

Hi Albert. In case it helps I've attached my test .story. I have tweaked code slightly to get rid of the [Object object] error I was getting but it all seems to work well. You'll find the javascript code on the last slide. Happy to share the spreadsheet too if you want to message me with your google details.

Ashley Terwilliger

Hi Yoni,

I'm sorry to hear that this doesn't work for you in IE9, but as Jacinta mentioned it's an aging browser so encouraging your users to update is a good recommendation. Since we don't support exporting variables to an excel document or Google spreadsheet I'll defer to the community for assistance. 

Norman Lamont

Hi.  I've been trying for a few hours to get this working but without success.  I'm sure I've got everything correct in the code, but my spreadsheet doesn't update and I don't get any popup in the Storyline course confirming the data has been sent.

Can I just check a couple of things?

1) does this work in Storyline 1?  My client isn't on v2 so I'm trying it in V1.  I did try the Storyline 2 version Louise put up, substituting my my Google URL and variable names, but again nothing happened.

2) does the page that does the sending have to be a Quiz Results page? I've just been using an ordinary page. I set the values of the variables in the page, just for test purposes and attached the 'sending' script to a button.

I'm fairly sure of my syntax and have included the JQuery link in the header.  I'm not hosting it on an LMS, just on a website, since the point of doing it is for a client who doesn't have an LMS.

The variable names definitely reflect the column headers in the spreadsheet. Any other stumbling blocks I should check?

Louise Lindop

Hi Norman.

I did a test in SL1 and it all worked as it did in SL2. I also did a test to see if it all worked OK without a results slide and it also worked as it did with results slide. I also am testing on a website (no LMS). There is no message displayed in SL when the data is sent. I'm not sure what else to suggest. If I were you I would just start again at the beginning with fresh spreadsheet and SL file, but perhaps you have tried that?

Louise

Steve Flowers

Hi Norman - 

Since the script can bomb on any number of things, I'll usually run the JS console in the browser to watch for errors. This will quickly tell you if the problem is in your send function or if there's something else going on.

Another method you can use in a pinch is editing the user.js file on the server. Many FTP clients allow for direct edit and save of the file (auto-upload of changes). This would make it easy to insert an alert, something like alert("here"); to see how far through the script it goes. Wherever the alert stops working, the problem is somewhere above that.

If you don't get errors and the alert works, it may be that something is going on with your field ID's or the structure of your endpoint string. 

Do you have a link you can share here?

Kate Robertson

Hi Norman, I haven't tried it in SL1 but I do use it on a normal slide, i.e. not a results slide and it works well. Just a thought, have you made your google doc public? If it's not shared it won't work.

Louise, thanks for the updated code to avoid the [object] alert, I have pinched that!

 

 

Norman Lamont

One thing I notice when I do this is that when I select Tools > Script Editor I get a popup headed Create Script For ...  but doesn't list the title of my spreadsheet. (Attached screen shot) 

I've just been clicking Close on this and the script editor opens.  Do you think I'm  going wrong at this step?

Norman Lamont

Success!

This time I overwrote the function which probably explains why it works now. I must have had function calls within a function call previously.

I'm finding it works - and I'm delighted and grateful -  but when I hit the send button I get a popup saying [object][object]   Does anyone know how to get rid of that?  Is it maybe caused by this line in the Storyline script?

success: function(data)
{
alert(data);
}

 

Kate Robertson

Hi Norman

I am glad you have managed to get it working. Louise changed the code slightly to get rid of the popup so that section should read:

success: function(data){

console.log(data);

},

error: function(err) {
console.log('Error:', err);
}

 

Although, your code seems to work as well!

Steve Flowers

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();
}
Laura Brunning

Hi,

We're using the form solution to send variables to a Google sheet.  All works OK, but only if I edit the story.html file and add in the  <script type="text/javascript src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> bit in the header.

 I've tried the solution above to automatically write it to the header and added it to a trigger before the rest of the javascript stuff kicks in, but this way, it doesn't send the data to the Google sheet.  It'll only work if I add it manually to the output file before zipping.

Am I missing something really obvious? Any help would be most appreciated!

 

Steve Flowers

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.