Thursday, February 22, 2018

Setting up a Google Docs Form for Second Life Interaction

I'm using Google Docs now with Second Life for tracking a few different things, and the basic set up is the same, so I've decided to just make this it's own post, that I can reference later.  For this example, I'm using aspects of the sales tracker script, but it can be adapted for any script.

Google Forms can be easily used to track various inworld activities in Second Life.  I am currently using it to track visitors to my store and for tracking sales in my store.  It's free, it doesn't require running or setting up a webserver or PHP or SQL.  I will say up front, I have no idea if there are API limits at all to this.  My use is extremely low traffic.  I suspect that, since it's Google, it's pretty robust.

Firstly, go to your google drive, at drive.google.com.  Create a new form and name it something useful.  In this case, I used "Gique Sales Tracker".


Change the default included field to "Short Answer" and give it a useful name.  On a side note, all of these names are independent of anything in Second Life and can be anything you want them to be.  The interaction occurs via some key values, not the form names or LSL variable names.  Add additional form fields, all "Short Answer" using the + icon on the side.  For the sales tracker, I used "Avatar", "Item", "Price", and "Location".  If you are using this framework for your own projects, you can add as many or as few fields as needed.  NOTE:  The system adds date and time on it's own.


Now near the top of the form composer, select "Responses", and click the little green icon.  Select "Create new Spreadsheet", and name it whatever you'd like.  This will cause the form to dump all responses to a useful spreadsheet as they come in.  Because of the way Google works, you can even watch this happen in real time.  The system automatically adds a date and time column.  Notice the column names are the names of the form fills you entered earlier.



This next step is the trickiest part of this entire deal, but it's not as hard as it seems, so don't be deterred.  At the top of the form creation page, near "Send" is an eyeball icon, this will allow you to preview the form.  Click this, and it will open the form in a new tab on your browser.  If you want to test the functionality of the form, you can enter values into the form manually here and submit them and they should show up in your spread sheet.  This page will look very similar to the form creator page, except the creation buttons will be missing.

You will need to make some notes here.  I'd recommend using a notepad style program, you can write them down if you want, but at least one of the values you're pulling next is very long and complex, so I'd recommend something you can cut and paste to.  You will need all of these values in Second Life in the script, you can put them directly in the script, or an SL notecard even.

Right click on the Form Preview page, and select "View Page Source".  This may be called something else depending on your browser, but the idea is to view the code that makes the form page.  This will open a tab or a window with a mess of code.  You'll want to do a "Find".  In Windows, you can do this with "Control+F", I believe it's similar in Mac and Linux.  In the find box, search for "entry.", including the period.  Chrome highlights all occurrences of the search term, some browsers may require multiple searching to cycle through each occurrence.  What you are looking for, is the number that occurs just after "entry."


Record these numbers, and what they correspond to.  The numbers should occur in the order you added them to your form, but you can verify this by scanning back a bit in the code, the form name is listed under a tag "aria-label".  I've highlighted above where it shows "Avatar Name", notice lower in the example it reads "Item", "Location", and "Price".  The numbers from this example are, 1518898711, 1485797246, 1639291941, and 1768330639.  Your numbers WILL be different.  Using those 4 numbers will not work for you.

Also, in case anyone thinks they want to be clever, I created a dummy form for this example, so these numbers are not the numbers I use for my actual tracker.

Once you have these numbers, you can close the source code.  You can also close out the preview form if you want.  You will also need the form id, which can be found in the URL box at the top of your browser.



I've highlighted what you need above, but you want everything BETWEEN the slashes.  The actual URL for the example is here:

https://docs.google.com/forms/d/1zGN8eH4ZbwqZWEVw4qFB-nS9WrGv7yEeYWm8QzJ1MkM/edit

You want everything in between the slashes, highlighted above.  You do not need the slashes.  Mark this down as your form key.

And that's all that you need for basic set up of a Google Form for use in an SL script.  I'll post about a couple of projects using this form later.

A copy of the script that can be used with this set up can be gotten here.





1 comment: