# GA Audit per-project debugging and cleanup

## What was fixed

- **Run audit**: Uses the currently selected project when saving the audit (resolved project ID).
- **History**: Loads and displays history for the currently selected project only.
- **Checklist state**: Read/write of checked items (including “Data filters reviewed” and other items) uses the current project.
- **Framework vs GA4**: The framework events sent with the audit use the current project’s linked framework (`getFrameworkEventNamesForAudit` uses resolved project ID). On project switch, the Framework vs GA4 card is hidden and its content cleared.
- **Data Filters / results panel**: The whole results block (Property info, Framework vs GA4, filter controls, Findings) is hidden on project switch; content is cleared (findings, framework validation, property details, score/summary) and filter dropdowns reset to “All” / “Category” so the next audit uses default filters.
- **Project switch**: When you change project, the GA Audit tab resets to the empty state and shows the new project’s checklist and history.

## Debugging (browser console)

1. **See which project the GA Audit is using**
   - In the console run: `window.GA_AUDIT_DEBUG = true`
   - Then open the GA Audit tab or run an audit. You’ll see logs like:
     - `[GA Audit] loadGaAuditHistory projectId= <uuid>`
     - `[GA Audit] getGaAuditChecklistState projectId= <uuid>`
   - Turn off: `window.GA_AUDIT_DEBUG = false`

2. **Current project ID**
   - Run: `window.getResolvedCurrentProjectId()`
   - This is the ID used for GA Audit (and other per-project features).

## One-time cleanup (if audit looked shared before the fix)

- **In-session reset**  
  In the console run:  
  `BlueprintGaAuditResetForProject()`  
  This clears in-memory audit result, invalidates caches, and resets the GA Audit UI. Then switch project or open the GA Audit tab to load the correct project’s data.

- **Legacy global checklist state**  
  If you ever used the app without a project (no project selected), checklist state may have been stored under a single key. You can clear it with:  
  `localStorage.removeItem('gaAuditChecklist')`  
  (Only do this if you want to wipe that fallback state.)

- **Audits saved with wrong project_id**  
  Fixes only affect new runs and UI. Old rows in `ga4_audit_results` that were saved with the wrong `project_id` (e.g. before this fix) stay as-is. To correct them you’d need a one-off SQL or script that sets `project_id` based on your own rules (e.g. by `measurement_id` or date). Supabase Dashboard → SQL Editor is one place to run such updates.
