npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gridsome-plugin-google-sheets-post

v3.0.6

Published

Post data to your Google Sheets document from Gridsome website.

Downloads

91

Readme

  • This plugin for posting any data from form to Google Sheets.
  • Useful for contact forms etc.
  • No limitations for form element.
  • Built-in hCaptcha

Get started

gridsome.config.js

module.exports = {
  plugins: [
    {
      use: "gridsome-plugin-google-sheets-post"
    }
  ]
}

Usage 1

With built-in submit events, captcha and auto forming request

Your Vue template:

<gsp-form :gscriptID="gscript" :siteKey="siteKey">
    <input type="text" placeholder="Your data" data-gsp-name="data-name" :data-gsp-data="data" v-model="data"/>
    <button>Send</button>
</gsp-form>
<script>
export default {
  
    data() {
      return {
       
        gscript:  process.env.GRIDSOME_GSCRIPTID,
        siteKey:  process.env.GRIDSOME_SITEKEY,

        data: ''

      }
    }
}
</script>

Watch result with $response

Usage 2

You can use only function for sending data to Google Sheet $gspPostForm

<script>
export default {
  
    data() {
      return {
       
        gscript:  process.env.GRIDSOME_GSCRIPTID,
        siteKey:  process.env.GRIDSOME_SITEKEY,

        data1: '',
        data2: ''

      }
    },

    methods: {
        onSubmit: async function () {
            let response = 'data1=' + encodeURIComponent(this.data1) + '&data2=' + encodeURIComponent(this.data2)
            await this.$gspPostForm(this.gscript, response)
            }
        }
    }
}
</script>

Forming Google Sheet

You may use script template below and follow the steps:

  1. Create Google Sheet doc in your account: first column named sn + columns named as your fields in form + column named timestamp. You may rewrite script and use other tech columns as you like.
  2. Open Apps Script and write script for posting data in doc + you can send email notifications for any person (admin or user). See example below.
  3. Than deploy script. If you use script from example below: choose setup function and run this; choose doPost and Deploy it. Give writes for 'all' so your website can write to the sheet.
  4. Copy script id from deploying and setup environmental variable

Script example: Please watch sendEmail function, you need to edit it according to your data. Also you can choose not to send email, so just delete this function.

function doPost(e){
  return handleResponse(e);
}

//  Enter sheet name where data is to be written below
var SHEET_NAME = "Sheet1";

var SCRIPT_PROP = PropertiesService.getScriptProperties(); // new property service

function handleResponse(e) {
  // Google the LockService 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("key"));
    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 if(headers[i] == "sn") {
        row.push(sheet.getLastRow());
      } 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]);
    
    //send email
    sendEmail(e.parameter);
    
    // return json success results
    return ContentService
          .createTextOutput(JSON.stringify({"result":"success"}))
          .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("key", doc.getId());
}

function sendEmail(data) {

  var email = ''; // automatic email responce to user
  var emailFrom = '';
  var emailAdmin = ''; // notification for admin

  var data = '';
  var timestamp = new Date();
  var adminBody = '';
  var userBody = '';
  var userTitle = '';

  for (let key in data){
   if(data.hasOwnProperty(key)){
     if (key === 'data') { name = data[key]; }
     if (key === 'email') { email = data[key]; }
   }
  }

  adminTitle = 'New form apply';
  adminBody = 'New form apply on website';
  userTitle = 'Your application';
  userBody = 'Your apply has been sent';

  if (email != '') {
    GmailApp.sendEmail(emailAdmin, adminTitle, '', {
      name: 'yourwebsite.com',
      from: emailFrom,
      htmlBody: adminBody
    });
    
    GmailApp.sendEmail(email, userTitle, '', {
      name: 'yourwebsite.com',
      from: emailFrom,
      htmlBody: userBody
    });
  }
}

TODO

  • Move to another captcha
  • Make local registration of component possible

Troubleshoting

If you have any troubles, create issue on Github