Using Google For Work / Google Apps To Automate Giveaways

Raffle tickets rolled up waiting to be handed out.

Pulling a ticket blindly from the fishbowl, the winner was selected.  How many have seen this a time or two?

Vino Pair is excited to be a vendor in Kansas City's first annual, sold out Uncorked Event.  Wine makers from all over the world and local food trucks will converge on Union Station, March 26th. There are many giveaways that Vino Pair will be offering all the 3,000 attendees.  Does Vino Pair give out tickets and pull from a fishbowl, hat, etc? No, that's not scaleable with 3,000 people.  Plus, it's 2016.  Is there another, simple option?

Google For Work aka Google Apps, Google Forms, QR Codes, and a little Google App Script and Vino Pair has the following:

  • Easy way to get to Google Form via QR code.
  • Google Form that accepts first, last name, email.
  • Google App Script that gets the count of entries, picks a random winner.
  • Google App Script also emails the winner and Vino Pair.
  • Google App Script "Pick Winner" routine can be activated from a mobile device.
  • No computer is needed to activate winners, just a mobile phone with the Google Drive App.

Here's the Google Form that was used.

Google form editor page

Google form editor page

Assumptions:

  • Most people coming to a wine event are going to bring their smart phones for photos.
  • If there's a group, someone in the group is bound to have smartphone that all can use.
  • Once the link is scanned at the booth, entries can be entered at the user's discretion.
  • Allows easy flow through booth using technology and eliminates the need for paper.
  • Some people will not be able to enter the contest and that's okay.
  • Email will work to notify winners so giveaway items are handed out same-day.

Recreating the example is simple.

Step 1 - Create a new Google Form

After creating the Google Form, nab the Form ID from the url.  See below - the ID is between the red lines.

google form url example

google form url example

Step 2 - Click the three dots in the top right of the Form editor page.  A menu will appear. Select the script editor from the list of options and your screen should look like the following.

Google script editor page

Google script editor page

Put the ID captured from the above step into the code below where it has -------------Google Form ID from URL------------.

function myFunction() {
 var form = FormApp.openById('-------------Google Form ID from URL------------');
 var formResponses = form.getResponses();
 var i = Math.floor(Math.random() * formResponses.length) + 0
 var formResponse = formResponses[i];
 var itemResponses = formResponse.getItemResponses();
 var winning_first_name = itemResponses[0].getResponse();
 var winning_last_name = itemResponses[1].getResponse();
 var winning_email_address = itemResponses[2].getResponse();
 sendemail(winning_first_name,winning_last_name,winning_email_address)
}

function sendemail(fname,lname,email) {  
   MailApp.sendEmail({
     to: email,
     cc: "mike@vinopair.com",
     subject: fname + " Is A Winner!!!",
     htmlBody: "Vino Pair Giveaway Winner Is = " + email + " -- " + fname + " " + lname + " - Please come to the Vino Pair booth to claim your prize!!"     
   });
 }

function onOpen(e) {
  var menu = FormApp.getUi().createAddonMenu(); // Or DocumentApp or FormApp.
  menu.addItem('Start workflow', 'myFunction');
  menu.addToUi();
}

Change the email routine to accurately reflect your giveaway.  Name your project.  Save the code and publish it. You need to enter a description of the code and accept some permissions on your Google Apps account.  It only takes a few seconds and your code is published, then it can be used in your Google Form.

The function called onOpen(e) fires when the Google Form is opened.  This code instructs this Google Form to add a menu option.  This is how it appears in the Google Form once it's published.

Click the puzzle piece to run the script and pick a winner.

Click the puzzle piece to run the script and pick a winner.

Step 3 - Now that the form is complete, it's time to create the QR codes. 

Googled 'QR Code maker' and this was the first result.  Just enter the url of the form into the QR code creator webpage and hit the create button.  You'll be able to download an image of the QR code after a moment from their sponsors.  Now, just print out the QR code and make it available at your booth.   When the code is scanned the user is taken to the form.  Here's a sample screen shot from an Android device.

google form on an android device

google form on an android device

Step 4 - Finally, the form security options will need to be adjusted in order to make sure customers can access your Google Form.   While on the Google Form page, click the gear and the make sure to change the setting to look like these settings below.

Google Forms settings

Google Forms settings

Save your settings.  To select a winner, open the Google Drive App, select the Google Form, and click the puzzle piece.

mobile google form edit view with google apps script puzzle piece shown

mobile google form edit view with google apps script puzzle piece shown

When the winner is selected, simply pull up the email that was cc'ed to you for verification purposes.  Done.

Problems:

  • A person can enter multiple times, but could be eliminated if login was required.
  • The script does not remember who it picked previously.
  • A winner can win multiple times.

Obviously it needs a little work, but for only 15 minutes of work, the results were pleasing.