Google Apps Script

Step‑by‑Step Guide to Google Apps Script Ecommerce Web App Deployment

Learn how to turn a Google Sheet into a live ecommerce order form with Google Apps Script. This guide walks you through prerequisites, deployment, testing, and common pitfalls.

You're ready to let customers place orders directly from a Google Sheet‑based form, but you aren't sure how to turn the script into a public web app without exposing your data or breaking the flow. This article answers that exact question and gives you a clear, ordered path to a safe Google Apps Script ecommerce web app deployment.

Prerequisites and Planning

Before you click Deploy, make sure you have the following in place:

  • Google account ownership – the account that owns the spreadsheet and script must be the one you will use for deployment.
  • Google Sheet that will store orders (e.g., columns for product ID, quantity, customer name, email, and status).
  • Apps Script project with at least two files:
    • Code.gs – server‑side functions that read/write the sheet and handle form submissions.
    • Index.html – the front‑end form shown to customers.
  • Basic knowledge of HTML forms and JavaScript google.script.run calls.
  • Clear decision on who may access the web app: Anyone, even anonymous (public) or Only users in your domain (restricted).

Write down any external services you plan to call (payment gateway, email API). Those will need additional OAuth scopes and may require a Google Cloud project.

Step‑by‑Step Deployment Guide

  1. 1. Prepare the script files

    In the Apps Script editor, create Code.gs with functions such as doGet(e) (to serve the HTML) and processOrder(formData) (to validate and write a row). Keep the code modular – separate validation, sheet writing, and email notification into their own functions. Example skeleton:

    function doGet(e) { return HtmlService.createHtmlOutputFromFile('Index'); } function processOrder(form) { var sheet = SpreadsheetApp.openById('YOUR_SHEET_ID').getSheetByName('Orders'); // Simple validation if (!form.productId || !form.quantity) { return {status: 'error', message: 'Missing fields'}; } sheet.appendRow([new Date(), form.productId, form.quantity, form.name, form.email, 'Pending']); // Optional: send confirmation email MailApp.sendEmail(form.email, 'Order Received', 'Thank you for your order.'); return {status: 'success'}; }

    Replace YOUR_SHEET_ID with the actual spreadsheet ID. Save the file.

  2. 2. Build the front‑end form

    Create Index.html. Use plain HTML and a tiny script that calls google.script.run.withSuccessHandler(...).processOrder(form). Example:

    <!DOCTYPE html> <html> <head> <base target="_top"> <style>body{font-family:sans-serif;max-width:400px;margin:auto;}</style> </head> <body> <h2>Place Your Order</h2> <form id="orderForm"> <label>Product ID:<input name="productId" required></label><br> <label>Quantity:<input name="quantity" type="number" min="1" required></label><br> <label>Name:<input name="name" required></label><br> <label>Email:<input name="email" type="email" required></label><br> <button type="submit">Submit</button> </form> <div id="msg"></div> <script> function handleSubmit(e){ e.preventDefault(); const form = Object.fromEntries(new FormData(e.target)); google.script.run.withSuccessHandler(function(res){ document.getElementById('msg').innerText = res.status==='success' ? 'Order placed!' : res.message; if(res.status==='success') e.target.reset(); }).processOrder(form); } </script> </body> </html>

    Keep the UI simple – the web app runs inside a sandboxed iframe, so avoid external CSS libraries unless you host them on a trusted CDN.

  3. 3. Set the required permissions

    When you run the script for the first time, Apps Script will ask for scopes such as https://www.googleapis.com/auth/spreadsheets and https://www.googleapis.com/auth/mail.send. Review them carefully. If you only need to write to the sheet, you can remove the email part to avoid the extra scope.

    To see the list, open Project Settings → Scopes in the editor. Reduce scopes whenever possible – fewer scopes mean a smoother review if you later publish the app publicly.

  4. 4. Deploy as a web app

    1. Click Deploy > New deployment in the Apps Script UI.
    2. Select Web app as the deployment type.
    3. Give the deployment a meaningful description (e.g., "Initial public order form").
    4. Under Execute as, choose Me (owner) so the script runs with your permissions.
    5. For Who has access, decide:
      • Anyone – the form is public; users do not need a Google account.
      • Anyone with the link – same as above but the URL is not indexed by search engines.
      • Only myself – useful for testing.
      • Anyone in your domain – restricts access to your organization’s Google Workspace accounts.
    6. Click Deploy. Copy the generated URL – this is the live form.

    Remember: changing the access level later requires a new deployment version.

  5. 5. Test the live URL

    Open the URL in an incognito window (or a different browser) to simulate a real customer. Submit a test order and verify:

    • The confirmation message appears.
    • A new row is added to the Orders sheet.
    • If you enabled email, check the inbox for the receipt.

    If anything fails, open the script editor, click View > Logs or use console.log statements inside processOrder to debug.

Common Mistakes and How to Fix Them

  • Wrong spreadsheet ID – The script will throw a “Spreadsheet not found” error. Double‑check the ID from the sheet’s URL.
  • Insufficient permissions – If the web app is set to run as “User accessing the web app” and the visitor is not logged in, the script cannot write to the sheet. Always keep Execute as Me for public forms.
  • Using google.script.run inside a form without preventing default submission – The page reloads before the async call finishes. Use event.preventDefault() as shown.
  • Exposing sensitive data – Never embed API keys or private sheet ranges in the client‑side HTML. Keep all secrets in the server‑side .gs file.
  • Forgot to set the access level to “Anyone” – The URL will show a Google sign‑in prompt, blocking customers. Re‑deploy with the correct setting.

Realistic Example: A Small Clothing Store in Karachi

Ali runs a boutique that sells T‑shirts online. He wants a simple order form that feeds directly into a Google Sheet, which he later imports into his accounting software.

  1. Ali creates a spreadsheet Ali_TShirts_Orders with columns: Timestamp, SKU, Qty, Customer Name, Email, Status.
  2. He writes the Code.gs and Index.html files exactly as described, replacing YOUR_SHEET_ID with the ID of his sheet.
  3. Because Ali only needs to collect orders (no payment integration yet), he removes the MailApp.sendEmail line to avoid the email scope.
  4. He deploys the web app with access set to “Anyone”. The generated URL is https://script.google.com/macros/s/AKfycbx.../exec.
  5. Ali embeds the URL on his Shopify store’s “Contact” page using an iframe. Customers can now place orders without leaving the site.
  6. After a week, Ali checks the sheet – it has 23 rows, each with correct data. He adds a column “Paid?” and later updates it manually when he receives cash on delivery.

This workflow costs nothing beyond the free Google account, and Ali can scale by adding validation rules or connecting to a payment gateway later.

Checklist Before You Go Live

  • ✅ Google Sheet ID correctly referenced in Code.gs.
  • ✅ All required OAuth scopes reviewed and minimized.
  • ✅ Deployment access set to the intended audience (public vs domain).
  • ✅ Form fields have required attributes and basic client‑side validation.
  • ✅ Server‑side validation in processOrder to guard against malformed data.
  • ✅ Test order submitted from an incognito window; data appears in the sheet.
  • ✅ Error handling displays user‑friendly messages (e.g., "Please fill all fields").
  • ✅ Backup strategy – enable File > Version history for the spreadsheet and script.
  • ✅ Optional: Set up an onEdit trigger to flag duplicate orders.

Conclusion

Deploying a Google Apps Script ecommerce web app is a low‑cost way to capture orders directly into a spreadsheet. By following the steps above, you can launch a functional form, keep data secure, and avoid the most common pitfalls. When you’re ready to expand – for example, adding payment processing or integrating with a VPS‑hosted storefront – you already have a solid data foundation.

Need a ready‑made codebase or help customizing the workflow for your business? View the Apps Script ecommerce source‑code package. If you have questions about deployment, triggers, or permissions, ask us for support.