Google Apps Script

Google Apps Script Ecommerce Source Code: Code.gs vs HTML Files and Cash‑Flow Risks

A practical guide that explains the roles of Code.gs and HTML files in a Google Apps Script ecommerce web app, highlights cash‑flow and downside risks, and provides a step‑by‑step setup checklist.

When you build a lightweight ecommerce front‑end with Google Apps Script, the two core file types you’ll see are Code.gs (the server‑side script) and HTML files (the client‑side UI). Understanding what each does, and the hidden cash‑flow or downside risks, lets you decide if this approach fits your budget before you invest time or money.

Direct answer: What Code.gs and HTML files do

Code.gs runs on Google’s servers. It contains the business logic – reading and writing to Google Sheets, handling payments, creating order records, and responding to web‑app requests. HTML files are served to the browser; they hold the visual layout, form fields, and client‑side JavaScript that calls the server functions via google.script.run.

In short, Code.gs = back‑end, HTML = front‑end. Both are required for a functional ecommerce web app.

Prerequisites before you start

  • Google account with access to Google Drive and Google Sheets.
  • A Google Sheet that will store product data, inventory, and orders.
  • Basic knowledge of JavaScript (both server‑side and client‑side).
  • Understanding of Google Apps Script quotas (execution time, daily calls, and URL‑fetch limits). See the official quota guide.

Step‑by‑step: Building and deploying the web app

  1. Create the project – In Google Drive, click New → More → Google Apps Script. Name it ecommerce‑app.
  2. Add Code.gs – Paste the skeleton below (only the essential parts are shown). Adjust the spreadsheet ID and column indexes to match your sheet. function doGet(e) { return HtmlService.createHtmlOutputFromFile('index'); } function getProducts() { const ss = SpreadsheetApp.openById('YOUR_SHEET_ID'); const sheet = ss.getSheetByName('Products'); return sheet.getDataRange().getValues(); } function placeOrder(order) { const ss = SpreadsheetApp.openById('YOUR_SHEET_ID'); const sheet = ss.getSheetByName('Orders'); sheet.appendRow([new Date(), order.email, order.productId, order.quantity, order.total]); return {status: 'success'}; }
  3. Create the HTML UI – Add a file named index.html. Include a simple product list and a checkout button. <!DOCTYPE html> <html> <head> <base target="_top"> <script> function loadProducts() { google.script.run.withSuccessHandler(renderProducts).getProducts(); } function renderProducts(data) { // data is a 2‑D array; build a table (omitted for brevity) } function submitOrder() { const order = {email: document.getElementById('email').value, productId: 1, quantity: 1, total: 20}; google.script.run.withSuccessHandler(alert).placeOrder(order); } window.onload = loadProducts; </script> </head> <body> <h1>My Simple Store</h1> <div id="product-list"></div> <input id="email" type="email" placeholder="Your email"> <button>Buy Now</button> </body> </html>
  4. Set permissions – Click Deploy → Test deployments first. Choose Execute the app as: Me (owner) and Who has access: Anyone (or Anyone with the link for a private beta). Save.
  5. Deploy as a web app – From the same menu, select New deployment → Web app. Copy the URL; this is your storefront.
  6. Test the flow – Open the URL in an incognito window, place a test order, then verify the Orders sheet received a row.

Cash‑flow and downside risk checklist

Even though Apps Script is free for most small‑scale uses, there are hidden cost drivers you should evaluate before committing.

  • Quota limits – Exceeding daily execution time or URL‑fetch calls can halt your store until the quota resets (usually 24 hours). This can mean lost sales.
  • Google Workspace licensing – If you need a custom domain or advanced security, you may have to upgrade to a paid Google Workspace account (starting around $6 USD per user per month).
  • Third‑party payment integration – Apps Script cannot host PCI‑compliant payment pages directly. You’ll need to redirect to a gateway (e.g., Stripe Checkout). Transaction fees are charged by the gateway, not by Apps Script, but you must budget for them.
  • Data‑export costs – Exporting large order histories to CSV or external ERP systems may require additional scripts that consume more quota or trigger paid Google Cloud services.
  • Support and maintenance – If you’re not comfortable debugging server‑side errors, you may need to hire a developer. Hourly rates can range from $30‑$80 USD, adding to cash‑flow risk.

Assess these points early. If your projected monthly orders exceed 1,000 or you expect heavy traffic spikes (e.g., flash sales), consider a dedicated hosting platform instead.

Realistic hypothetical example

Ali runs a small handmade‑soap business in Karachi. He wants a quick online catalog without paying for a Shopify plan. He creates a Google Sheet with 30 products, each row containing Name, Price, Stock, Image URL. Using the steps above, he builds a web app that shows the catalog and records orders in a second sheet.

During the first month, Ali receives 120 orders. Each order triggers two server calls (one to read the product, one to write the order). That totals 240 calls – well within the free quota (6 million calls per day). However, on the 31st day, a local influencer shares the link, and traffic spikes to 1,200 orders in 24 hours. The script now makes ~2,400 calls, still under the limit, but the execution time per call rises because the getProducts function reads the entire sheet each time. Ali notices the checkout button becomes unresponsive for a few seconds, leading to abandoned carts.

Ali’s options:

  • Cache the product list using CacheService to reduce read operations.
  • Move the product data to a separate sheet that is read once per session.
  • If traffic continues to grow, migrate to a low‑cost VPS hosting a Node.js app, where he can control scaling.

This example shows how a seemingly free solution can generate hidden cash‑flow pressure when traffic grows.

Common mistakes and how to fix them

  • Reading the whole sheet on every request – Use CacheService or store data in a PropertiesService object after the first load.
  • Deploying with "Anyone" access without authentication – This opens the app to spam orders. Add a simple email verification step or restrict access to logged‑in Google users.
  • Hard‑coding spreadsheet IDs – If you clone the project for a new client, you’ll need to update the ID manually. Store the ID in a script property instead.
  • Ignoring execution logs – Open View → Logs after a failed order. Errors like Exception: You do not have permission to call SpreadsheetApp.openById indicate a permission mismatch.
  • Not handling quota errors – Wrap server calls in try / catch and return a friendly message (“We’re experiencing high demand, please try again in a few minutes”).

Setup checklist

  1. Create a Google Sheet with Products and Orders tabs.
  2. Open Apps Script, add Code.gs with server functions (doGet, getProducts, placeOrder).
  3. Add index.html (or multiple HTML files) for the UI.
  4. Set deployment permissions: execute as owner, access for anyone with the link (or restricted as needed).
  5. Test the web app in a private browser window.
  6. Implement basic caching to protect against quota spikes.
  7. Document any third‑party integrations (payment gateway URLs, webhook endpoints).
  8. Plan for backup: schedule a daily export of the Orders sheet using a time‑driven trigger.
  9. Review cash‑flow: calculate expected monthly transaction fees from payment gateway + any Google Workspace costs.
  10. Decide on a go‑live date; prepare a fallback plan (e.g., static catalog PDF) if the script hits quota limits.

Conclusion

Code.gs provides the back‑end logic, while HTML files render the front‑end UI. Together they let you launch a functional ecommerce store without paying for a traditional platform, but you must monitor Google Apps Script quotas, potential Workspace licensing, and third‑party payment fees. By following the step‑by‑step guide, using caching, and keeping an eye on cash‑flow risks, you can decide whether this lightweight solution meets your business needs or if you should upgrade to a more robust hosting environment.

Ready to jump in? View the Apps Script ecommerce source‑code package. Need help deploying or customizing the workflow? Ask us about deployment or custom workflow support.