|
Welcome to the Google Sheets Tips newsletter #393, your Monday morning espresso, in spreadsheet form! ⚽️ We were bitten by World Cup fever in my house, watching matches together in the evenings. What a fantastic tournament, with drama in spades. Of course, I'm disappointed England didn't reach the final, but the I thoroughly enjoyed the ding-dong 6-4 third place playoff game against France. 🚴♂️ But, imho, there's an even better sporting spectacle happening in France at the moment: the Tour de France! Admittedly, it's more exciting if you're a cyclist yourself. There's a lot of team work and tactics going on in the background. What sometimes looks like a long line of riders grinding slowly and painfully up a mountain is really modern gladiators battling it out until there's one left standing. Along with the colorful motorcade and drama that surrounds every race, it's the greatest sporting spectacle on the planet imho ;) I love it! In today's tip, we're vibe coding an activity dashboard. Paying Workspace accounts have an Activity Dashboard tool in Sheets that tells you who's using the Sheet, on which days, etc. But it's not available for consumers. So today, we'll build our own with the help of Gemini! We'll build an Apps Script version that replicates most of the same features. Find it below... ➜ NewsI. ➜ Sheets Tip #393: Activity DashboardDid you know that Google Sheets on paid Workspace plans come with a built-in activity dashboard? You can find out who is viewing the Sheet, how many times, how many comments there are, etc. Unfortunately, this feature isn't available on consumer Google accounts. Instead, you can build one for yourself using Gemini and Apps Script. Previously this might have taken a day or two to build, or require hiring a professional developer. So it was probably a case of the juice not being worth the squeeze. Now however, the calculation is totally different. Copy the prompt below and follow the steps and you can build one in under 5 minutes! Let's see both in action: 📌 Workspace Accounts: Built-in Activity DashboardAccess the dashboard through the menu: Tools > Activity Dashboard For Google Workspace account users, the Activity Dashboard shows you who the viewers of your Sheet are, viewer and comment trends over time, the sharing history, and privacy settings (where you control your view history). For example: Notes: 1) You’ll only see activity from people in your organization or the people you see in Share > Advanced. 📌 Consumer Accounts: Vibe Code An Activity DashboardThe activity dashboard is not available for consumer (free) accounts. Instead, let's use Gemini to build a custom one for us. Phase 1: Get the Code
Phase 2: Add to Google Sheets
Phase 3: Authorize & Launch
The Prompt# Goal
Create a functional, bug-free "Activity Dashboard" modal popup (800x600px) for a personal Google Sheet that mimics the official Google Workspace Activity Dashboard.
# Critical Technical Fixes (To Prevent Infinite Loading/Spinner Freezes)
1. Chart Library Execution Sequencing:
- The frontend HTML must wait for `google.charts.load` to fully resolve *before* invoking the backend data fetch (`google.script.run`).
2. Bulletproof Comment Fetching (No Silent Crashes):
- Wrap the `DriveApp` comment retrieval inside a strict try-catch block.
- Crucially, test permission availability *before* looping through comments. If `DriveApp` throws an error or is blocked by missing project permissions, catch it immediately, log a warning, and fallback to returning an empty array `[]` for comments so that the rest of the dashboard (Viewers & Viewer Trend) still completely loads.
3. Empty Log Safety:
- The backend must gracefully handle a brand new or empty "SYS_ActivityLog" sheet without crashing (return empty default structures instead of null or undefined).
4. Global Error Visibility:
- Always chain `.withFailureHandler(err => ...)` on the frontend `google.script.run` call. If any backend error occurs, instantly hide the loading spinner and display the explicit error message text inside a red notification banner on the UI.
# Requirements
1. Trigger & Data Logging:
- On open, log the timestamp and current user's email (fallback to "Anonymous Viewer") to a hidden sheet named "SYS_ActivityLog". Create/initialize headers if the sheet does not exist.
- Add a custom menu "Analytics" > "View Dashboard" to open the modal.
2. Data Processing (Last 14 Days):
- Parse "SYS_ActivityLog" to aggregate daily viewer counts and compile a unique user list.
- Safely fetch sheet comment metrics using `DriveApp.getFileById().getComments()`.
3. Google Material UI Design:
- Layout: Clean sidebar navigation with three clickable tabs: "Viewers" (Default active view), "Viewer trend", and "Comment trend".
- "Viewers" View: Displays a vertical list of unique users with their last seen timestamp and a color-coded circular avatar containing the user's first initial (generated dynamically via CSS/JS from their email).
- "Viewer trend" & "Comment trend" Views: Display a "Total Count" metric card and a standard Google Column Chart mapping data over the last 14 days.
4. Privacy Notice:
- Include a small footer notice: "Charts do not include anyone who has opted out or accessed the file anonymously."
# Output
Provide a single `Code.gs` backend script and a single `index.html` frontend file ready to deploy. Ensure all asynchronous operations are defensively designed to guarantee data delivery.
Fixing ErrorsYou might run the prompt above and get code that works perfectly on the first try. But you might also run into an error, and that's ok. Simply describe what's happening and ask Gemini to fix the code. For example, one of my attempts wouldn't load properly. This prompt fixed the issue: When I tried this code, it got stuck on the loading spinner and would not show any actual data in the dashboard. Please fix this issue. If you enjoyed this newsletter, please forward it to a friend who might enjoy it. Have a great week! Cheers, |
Get better at working with Google Sheets! Join 50,000 readers to get an actionable tip in your inbox every Monday.
Brought to you by: Hi Reader, Welcome (back) to the Google Sheets Tips newsletter, issue #392, your Monday morning espresso, in spreadsheet form! Greetings from the East Coast of the US, where we've been under an Extreme Heat Warning for the past few days, with temperatures at a sweltering 100°F (feels like 114°F with humidity 🥵.) This follows on from the heat wave in the UK a week ago (where I was visiting family) and another in Germany the week before that (where my wife and I traveled for...
Hi Reader, Welcome to the Google Sheets Tips newsletter #391, your Monday morning espresso, in spreadsheet form! (Sorry there was no newsletter last week. I was sick!) This week we're looking at a cool use case for Google Sheets that most folks have no idea about. Creating QR codes! With a few simple formulas you can create QR codes in your Sheets that you could use to track inventory, accept invitations, or even print out to use at an event. First, a housekeeping announcement: after today,...
Hi Reader, Welcome to the Google Sheets Tips newsletter #390, your Monday Tuesday* morning espresso, in spreadsheet form! * public holiday in the US yesterday. Speaking of coffee, I usually work from my local coffee shop twice a week. It makes for a nice change of scenery from home. And everytime I order the same thing: a regular cappuccino, no frills, no syrups, no fancy milks. I think it says a lot about my personality and stage in life. As a working parent, neck deep in the world of AI,...