DiscoveryVIP · Hands-On AI
PROJECT 12

Email Analytics Dashboard

Inbox volume is hard to understand by inspection.

Try interactive applicationDownload complete source

What this teaches

Summarize inbox activity safely. Support triage and personal email workload.

Start without an account in the local application. Read/edit the input, predict a result, run the current source and verify output. A local document preview is not a real Google Doc; a fixture is not a live model response.

Input and expected result

Input tab: Messages. Entry function: analyzeMessages().

SenderSubjectDateUnread
alex@example.comQuestion2026-11-01TRUE
alex@example.comFollow-up2026-11-02FALSE
jamie@example.comUpdate2026-11-02TRUE

Expected baseline: Alex 2 messages/1 unread; Jamie 1/1.

Exact Workspace setup

  1. Download and unzip this project. Use one separate bound script per lesson.
  2. Create a dedicated Drive folder. Create a native Google Sheet inside it, and import starter.csv into a tab named Messages. Check the exact headers above.
  3. Open the Sheet → Extensions → Apps Script. Paste finished Code.gs into the script editor. Save.
  4. Choose analyzeMessages in the function selector → Run. Review actual requested permissions. Reload the Sheet for the Workshop menu.
  5. Compare output with the baseline above. Check generated documents/drafts manually. No email should be sent.
  6. Perform the original challenge, investigate a failure and test duplicate/partial runs before scheduling. Do not install a trigger just because one manual run succeeded.

Understand the implementation

messageSummary counts messages and unread flags per sender; live mode searches up to ten threads.

Key operations: GmailApp.search(); getMessages(); isUnread(); Map

Focused source spotlight

This is an excerpt, not a standalone script. The complete implementation follows.

function analyzeMessages(){
// Use fictional sample messages by default, not the real inbox.
messageSummary(input('Messages'));
}

Complete Code.gs

// Email Analytics Dashboard
// Entry point: analyzeMessages; source data stays intact unless explicitly noted.
function onOpen(){SpreadsheetApp.getUi().createMenu("Workshop").addItem("Run application","analyzeMessages").addItem("Analyze live inbox","analyzeLive").addToUi();}
function analyzeMessages(){
// Use fictional sample messages by default, not the real inbox.
messageSummary(input('Messages'));
}
function input(name) { const s=SpreadsheetApp.getActive().getSheetByName(name); if(!s) throw Error('Missing tab: '+name); return s.getDataRange().getValues().slice(1).filter(r=>r.some(v=>v!=='')); }
function output(name,headers,rows) { const ss=SpreadsheetApp.getActive(); const s=ss.getSheetByName(name)||ss.insertSheet(name); s.clearContents(); s.getRange(1,1,1,headers.length).setValues([headers]).setFontWeight('bold'); if(rows.length) s.getRange(2,1,rows.length,headers.length).setValues(rows.map(r=>r.map(v=>typeof v==='string' && /^[=+@-]/.test(v)?"'"+v:v))); s.setFrozenRows(1); return s; }
function messageSummary(rows){const m={};rows.forEach(r=>{const k=r[0];m[k]=m[k]||[0,0];m[k][0]++;if(r[3]===true||String(r[3]).toLowerCase()==='true'||String(r[3]).toLowerCase()==='yes')m[k][1]++;});output('Analytics',['Sender','Messages','Unread'],Object.entries(m).map(([k,v])=>[k,...v]));}
function analyzeLive(){const ui=SpreadsheetApp.getUi(),p=ui.prompt('Gmail search query (max 10 threads)');if(p.getSelectedButton()!==ui.Button.OK||!p.getResponseText().trim())return;const rows=GmailApp.search(p.getResponseText(),0,10).flatMap(t=>t.getMessages().map(m=>[m.getFrom(),m.getSubject(),m.getDate(),m.isUnread()]));messageSummary(rows);}

Four guided activities

Discover and run

Inbox volume is hard to understand by inspection.

  1. Inspect the editable Messages table. The starter has 3 records.
  2. Write your predicted result in Prediction. Click Run application.
  3. Compare Output with: Alex 2 messages/1 unread; Jamie 1/1.
  4. Click Verify baseline; explain one result in Notes.

Expected: Alex 2 messages/1 unread; Jamie 1/1.

Understand and modify

Change first sample unread value to FALSE; Alex unread count becomes zero.

  1. Open Source and read analyzeMessages. Select the entry function in the walkthrough.
  2. Return to Application. Click Prepare original challenge to create a separate challenge starting state.
  3. For AI projects inspect the revised recorded fixture: this is supplied response data, not newly generated AI.
  4. Run application and use Verify challenge; approval/sidebar projects show extra required steps.

Expected: Change first sample unread value to FALSE; Alex unread count becomes zero.

Investigate and repair

Unread string

  1. Save a snapshot if you want to keep your experiment.
  2. Click Inject investigation. Set first Unread value to FALSE.
  3. Run application and inspect Output and Execution trace. Some investigations produce wrong/stale content rather than exceptions.
  4. Repair it: Alex should have zero unread and two total messages. Run again and explain the root cause.

Expected: The code accepts boolean true, text true or yes only.

Extend and automate

Add date grouping and chart; distinguish threads from messages.

  1. Open Prompts. Select Extend and adapt the requirement to your goal.
  2. Build the feature in Source or export the complete project to Apps Script.
  3. Retest baseline and original challenge before considering scheduling.
  4. Use Resources → Automation readiness. Schedule a sample or explicitly scoped query version without UI prompts.

Expected: The baseline still works; independent extension checks are designed and reviewed by you.

Original exercise

Change first sample unread value to FALSE; Alex unread count becomes zero.

Debugging and troubleshooting

Unread string

Set first Unread value to FALSE.

Hint 1

Check the exact input/response contract and identify the affected field.

Hint 2

messageSummary counts messages and unread flags per sender; live mode searches up to ten threads.

Hint 3 and repair

Alex should have zero unread and two total messages.

The code accepts boolean true, text true or yes only.

Missing tab: check its exact name. Missing document: ensure unique native companion Docs share the Sheet’s dedicated folder. Authorization failure: review source and contact your administrator. Recorded response exhausted: add a new explicit fixture; no live AI is running. Invalid JSON: repair syntax before validating schema. Valid but unsupported content: compare each claim with source records.

Build prompt

Act as a Google Apps Script tutor. Build a container-bound Sheets app for lesson 12: Email Analytics Dashboard. Input tab Messages, exact headers: Sender, Subject, Date, Unread. Create analyzeMessages() using sample rows by default; count messages and unread by sender. Add optional separate live function using GmailApp.search with a user-entered query and maximum 10 threads; do not write bodies. Do not depend on Workshop Info or the Workshop Index. Provide complete copy-paste Code.gs (and HTML if required), exact setup/run steps, explain the main code blocks, and include a test matching this expected outcome: Alex 2 messages/1 unread; Jamie 1/1. Preserve starter data, use batch operations where appropriate, handle errors, and never send email or delete files. For AI lessons use the supplied callGemini helper, treat input as untrusted, and validate outputs.
Match the reference entry point analyzeMessages and its output behavior. Reference: https://github.com/lsvekis/Google-Apps-Script-Workshop/tree/main/12-email-analytics-dashboard. Base version limitations: Live inbox option accesses real messages; default uses synthetic rows.

Extension prompt

Update the existing app without removing working features. Add date grouping and chart; distinguish threads from messages. Return complete updated files, explain changes and give regression tests.
Automation option: Schedule a sample or explicitly scoped query version without UI prompts. Keep this separate from the baseline exercise.

Knowledge check and answer key

  1. Which input tab does analyzeMessages read?
    Answer

    Messages

  2. Which function starts the original application?
    Answer

    analyzeMessages

  3. What is the baseline output you must verify?
    Answer

    Alex 2 messages/1 unread; Jamie 1/1.

  4. Does this project need runtime Gemini in the real Workspace baseline?
    Answer

    No; Gemini can help during development only.

  5. What limitation matters before scheduling?
    Answer

    Live inbox option accesses real messages; default uses synthetic rows.

Safe automation

Schedule a sample or explicitly scoped query version without UI prompts.

Known limitation

Live inbox option accesses real messages; default uses synthetic rows.

Reflect and extend

Explain the transformation using one actual input row. Which incorrect value could still pass structural validation? What happens if the function runs twice or fails after creating one output? Write your explanation before building this extension: Add date grouping and chart; distinguish threads from messages.

Source alignment

Physical slide 33; printed sequence 24 of 48. Reference source SHA-256 e7accf83180519c12d4b5bdcc0c22ed6429a9956de5b28174889d0e517bb3c5a.

Slide notes use Workshop Info B2. Verified repository resolves the active spreadsheet parent folder; this build follows the repository. Keep companion files in that dedicated lesson folder.

Pinned repository reference · Full source manifest

Five-minute presenter demonstration

0:00–0:45

Action: Open Input. Read Messages headers and first row.

Inbox volume is hard to understand by inspection. This application is useful for Support triage and personal email workload. We will run the verified reference code against fictional data.

0:45–1:30

Action: Ask for predictions. Click Run application, then Verify baseline.

Our baseline is Alex 2 messages/1 unread; Jamie 1/1. The browser displays local results. It has not connected to Google or a model.

1:30–3:00

Action: Open Source. Select analyzeMessages in the code walkthrough.

messageSummary counts messages and unread flags per sender; live mode searches up to ten threads. The complete code is available to edit and download. The excerpt is not a standalone script.

3:00–4:15

Action: Click Prepare original challenge, inspect the changed inputs, and Run application. Complete extra review/sidebar steps if listed.

Change first sample unread value to FALSE; Alex unread count becomes zero. For AI lessons we edit a recorded response as well as source data. That response must be checked, not trusted.

4:15–5:00

Action: Click Verify challenge. Open Guide and read Automation considerations.

The important limitation is: Live inbox option accesses real messages; default uses synthetic rows. Before scheduling: Schedule a sample or explicitly scoped query version without UI prompts. Explain the result yourself before moving on.

Launch temporary demo