Google Apps Script tools that run a small marketing agency out of one Sheet.
A real Google Sheet on 2026-11-10 after Run report: the sidebar says the report is ready and the email went to the person running it (the Send to me first tick). The Report Log row is behind it.
The PDF that arrived by email. Its figures match fixtures/campaigns.csv. What ran is in docs/live-run.md.
The Summary tab that Rebuild summaries wrote for Tidewater Tutors.
A Data Studio (Looker Studio) report on the same Sheet, built by hand in the editor and shared by link: open the report. Its figures match the Campaigns tab in each client's own currency; the Summary tab converts to dollars, so the euro and pound clients differ there, and the report's spend column adds the currencies as they are. How it was built: docs/live-run.md.
A small agency repeats the same chores every month. Add up each client's ad spend, build a report, email it, and keep new leads and new clients in the right place. sheetdesk does these chores from one Google Sheet.
- Reports. Pick a client and a month in a sidebar and get a PDF report. Tick "Send to me first" and the PDF comes to you. Check it, then untick the box and send it to the client. A report to a client is refused for a month that is still running, and when Campaigns rows are left out of the figures the sidebar says how many and why before anything is emailed, and asks again.
- Month close. One button builds a report for every active client and emails each client the PDF, so it only runs for a month that has ended. A client is not emailed the same figures twice, and two closes cannot run at once: the second is refused with "Another run is closing the month. Try again in a minute." Before any email goes it says how many Campaigns rows are left out of the figures and why (no currency rate pulled yet, a date typed as text, a client name missing from the Clients tab), and it needs a second press when any are. Clients whose status is a typo are named, not skipped silently.
- Summaries. One tab per client with spend, clicks, conversions, cost per click and cost per conversion, by month and channel. Money in euros or pounds is converted to dollars with the rate of the day.
- Leads. Zapier or Make posts new leads to a web address. Each lead lands in the Leads tab once, even when Zapier retries. Apps Script web apps always answer HTTP 200, even for a lead they refuse, so add one step in Zapier or Make that stops the run when
okis not true, or a refused lead looks like a delivered one (webhook.md). - New clients. A Google Form collects a client's details, adds a row to the Clients tab and sends a confirmation.
- Ad costs and rates. Pull daily ad costs and currency rates into the Sheet. The ad cost pull starts on the first day of last month and runs through today, so a month that just ended is whole. One currency code the rates API does not know is named and skipped, and the other currencies are still pulled.
- Big sheets. Clean and roll up 50,000 rows inside Google's 6 minute limit, in several runs.
A sample agency, Fernwood Digital, runs on it: nine sample clients, 2,024 generated campaign rows and 300 generated leads.
Ready to use for: trying on a copy of a Sheet. On 2026-11-10 the menu, Set up, the summaries, the sidebar report with its PDF and the web app ran on a real Google account (what ran). Month close, the form trigger and the bulk job did not. See Limits.
A script that works once when you click it is not a tool. Here each chore is a module that is safe to run twice, checks its input, and has tests. Everything runs on sample data from a seeded generator, and the repo holds no personal data and no secrets.
flowchart LR
Z[Zapier or Make] -->|POST JSON with secret| W[doPost]
W -->|script lock, one row per client and lead_id| L[(Leads)]
F[Intake form] -->|installable trigger| I[onIntakeSubmit]
I --> C[(Clients)]
A[Ad platform API] -->|UrlFetchApp, retries, pages| S[syncAdCosts]
S --> K[(Campaigns)]
R[Frankfurter rates API] --> X[syncCurrencyRates]
X --> T[(Rates)]
K --> P[buildClientSummaries]
P --> U[(Summary tabs)]
K --> D[Doc from template]
D --> PDF[PDF in Drive]
PDF --> M[Email]
K --> B[bulk job, chunked]
B --> Q[(Clean and Rollup)]
B -. time trigger resumes .-> B
N[Menu, sidebar, dialog] --> P
N --> D
Apps Script loads every file in src/ into one global scope, so the modules call each other by function name. A trailing underscore marks a private function, which google.script.run cannot call.
| Piece | What it does | Page |
|---|---|---|
| Summaries, PDFs, month close | One summary tab per client from one getValues. A monthly report built from a template Doc, exported to a PDF with a stable name (a rerun replaces it), and emailed. |
summaries-and-pdfs.md |
| Menu, sidebar, dialog | onOpen menu, a sidebar with a client picker, a confirm dialog for the month close. Server functions check their input. |
menu-and-sidebar.md |
| Web app | doPost lead webhook with a shared secret, bad JSON and unknown field errors, one row per client and lead_id under a lock. doGet status JSON or an HTML dashboard. |
webhook.md |
| Intake form | An installable onFormSubmit trigger writes a client row and sends a confirmation. |
intake-form.md |
| Ad costs and rates | A UrlFetchApp client with backoff, Retry-After, pagination and a response check. Pulls daily ad costs and USD rates. |
ad-and-fx.md |
| Scale | 50,000 rows in chunks, a time budget, a saved cursor and a continuation trigger. | scale.md |
| Fake and data | The local fake of Google's services, and the seeded generator behind every number here. | fake-and-seed.md |
| Running it | Add a client, a channel or a column, rename the agency, read the logs, roll a version, fix a stopped trigger, and why each permission is asked for. | maintenance.md |
You need a Google account, Node 24 and clasp, Google's command line tool for Apps Script. The first part of these steps (clasp create, push and a deployment) was run on 2026-11-10 and is recorded in docs/live-run.md.
-
Switch on the Apps Script API for your account at script.google.com/home/usersettings. clasp cannot push without it.
-
Install clasp and sign in. The sign in opens a browser.
npm install -g @google/clasp clasp login
-
Make a new Google Sheet. In it choose Extensions, then Apps Script. This makes the script that belongs to the Sheet. In the editor open Project settings (the gear) and copy the Script ID.
-
Put the id in
.clasp.json, which already sets the folder and the file order. Do not commit your id.{ "scriptId": "PASTE_THE_SCRIPT_ID_HERE", "rootDir": "src", "filePushOrder": ["src/Config.js", "src/Util.js"] } -
Upload the code. If clasp asks whether to overwrite the manifest, answer yes, because
src/appsscript.jsonis the one to keep.clasp push
-
Reload the Sheet. A sheetdesk menu appears. Choose sheetdesk, then Set up. This creates the Campaigns, Clients, Leads and Rates tabs, saves a random webhook secret in the script properties, and sets the Sheet's time zone to the script's: the
timeZoneline ofsrc/appsscript.json, America/Chicago. Change that line before you push if your agency works in another zone. The first time, Google asks for permission:- Google shows "Google hasn't verified this app", because the script has not been submitted for Google's review. You deployed it yourself, so choose Advanced, then Go to the project, then Allow.
- Each permission and the call that needs it are listed in maintenance.md.
-
Load the sample data. In the Sheet open the Clients tab, click cell A1, then File, Import, Upload, choose
fixtures/clients.csv, set the import location to "Replace data at selected cell", leave the option that converts text to numbers and dates ticked (the code reads real dates), and import. Do the same withfixtures/campaigns.csvon the Campaigns tab andfixtures/rates.csvon the Rates tab.node scripts/seed.jsrewrites the fixtures. The leads file is not imported, because leads arrive through the webhook. -
Make the intake form. In the Sheet choose Extensions, then Apps Script to open the editor. Pick
installIntakeTriggerin the function list at the top and press Run. Accept the permission screen. When it finishes, the execution log at the bottom shows the form link. Open that link to see the form. -
Deploy the web app and copy its URL.
clasp create-deployment --description "v1" clasp list-deploymentsThe web app URL is
https://script.google.com/macros/s/followed by the deployment id, then/exec. These are the clasp 3 command names. Older clasp versions call themdeployanddeployments.
The manifest in src/appsscript.json already asks for the web app to run as you and to accept anonymous callers, because Zapier and Make do not sign in with Google. The shared secret is the only gate. Add AD_API_KEY in Project settings, Script properties, only if you point the ad sync at an API. The optional REPORT_CC and AD_API_BASE properties are explained in maintenance.md.
The click-through, a test lead with curl, Zapier and Make, and the 50,000 row job are in docs/try-it.md.
npm install
npm test # 511 tests
npm run lint # ESLint, zero warnings allowed
npm run mutation # well over an hour for the whole listThe tests run against a local fake of Google's services. npm test passes and npm run lint is clean. The mutation list holds 1,609 mutants (208 typed, 1,401 from the syntax tree, counted by node scripts/mutation.js --check) and 16 equivalent mutants that the run skips on purpose: each is a change that cannot alter what the code does, such as the T00:00:00Z added to a date that is read as the same instant without it, with its reason in EQUIVALENT in scripts/mutation.js. After the fifth review pass the mutants of the files that pass touched (Reporting.js, Menu.js, AdPlatform.js, Dialog.html, Sidebar.html) were run: 1,087 mutants (90 typed, 997 from the syntax tree). 1,074 were caught on the first run and 13 survived because a test asserted too little; the assertions were added and those 13 were caught on a rerun, so none of the 1,087 survives. The rest of the list was last run in full before this pass. The full set is rerun by the lead, and until then no total for the whole list is claimed here. After the blind recall that found the three problems of the changelog's newest entry, the 85 typed mutants of Reporting.js, Menu.js and AdPlatform.js (5 of them new) were run and all 85 were caught, and the 74 syntax tree mutants of the three functions that changed (runMonthClose, menuSyncAdCosts, fetchRates_) were run: 65 were caught on the first run and 9 survived. Two of the 9 are skipped as equivalent (a lock wait of 30001 or 29999 ms instead of 30000) and tests were added for the other 7, which were then caught on a rerun. The rest of the syntax tree mutants of those files were last run in full in the fifth pass and were not rerun after this change. docs/testing.md explains what a mutant is and what the tests check.
- Tested against a local stand-in written from Google's documentation, and run once on a Google account on 2026-11-10 across the menu, Set up, the summaries, the sidebar report with its PDF and the web app (details). Month close, the form trigger and the bulk job ran against the stand-in. The stand-in follows the documentation where it is specific and is strict where the documentation is silent, so it may refuse something the live service accepts.
- The stand-in's PDF is text with a PDF header, so page layout, fonts and the Doc to PDF conversion are shown by the report PDF from the live run above.
- Apps Script quotas apply. One execution runs at most 6 minutes. A consumer account has 90 minutes of trigger runtime a day, 100 email recipients a day, 20,000 URL fetch calls a day and 20 triggers per script (Workspace accounts have more of the first three). The scale job keeps inside 6 minutes with a budget check, and its chunk size and budget are set from these limits.
- The script's Frankfurter call is written to the reply shape checked by hand with a few
curlrequests on 2026-11-10. The ad platform is a sample one; a real platform would add OAuth, which this repo leaves out. - The report PDF is plain text and a table, with no agency name, logo or chart. The
monthly_budgetcolumn of the Clients tab is stored and no report reads it yet. - The web app has no rate limit and one secret for every caller. A secret in a URL can end up in logs. An optional lead field (email, name, phone, source, campaign, message) is stored as typed even when it looks wrong, and the reply lists it in
warnings. Nothing checks that an email exists or that a phone number is one. - The sidebar did render in Google's iframe and
google.script.runworked on 2026-11-10. The dialog and the web app dashboard page were not looked at in a browser there. - The CI workflow (
.github/workflows/ci.yml) runsnpm ci,npm run lintandnpm testonubuntu-latestwith Node 24, for pushes tomainand for pull requests. It runs green on GitHub. The mutation run is not in CI because it takes well over an hour. - Known and left as they are: the month close dialog counts as done only the clients that were built or had no data, so a rerun where every report is already current reads "0 done". A client name with no Latin letter or digit (Japanese, Arabic) gets the file name
clientand clashes with the next such name, which is named and left out. A repeatedlead_idfor one client is answeredduplicateeven when the other fields changed, and the first lead is kept. A client name with a dollar sign cannot be used in a PDF, and a backslash in a name has not been tried. A month close emails again when the figures changed by one cent. Each Campaigns row's converted spend is rounded to the cent before the rows are added, so a total can differ by a cent from converting the sum.
Google Apps Script (V8), clasp layout under src/, Node 24 with node:test, ESLint 9.
Daniel Alexis Cruz, github.com/Exalt24, dacruz.vercel.app. MIT, see LICENSE. Changes are in CHANGELOG.md.



