# AGENTS.md — Build guide for Simple Analytics

## Project scope
Collect minimal pageviews and named events from one owned site, aggregate common dimensions and provide a private dashboard plus CSV export.

Catalogue verdict: yes. Pageview analytics, events, dashboards, and exports are very buildable; paid value is hosted privacy posture, reports, reliability, and support.
Use the implementation prompt below to define the deliverable. Complete each phase's acceptance checks before extending the scope.

## Working agreement
- Inspect the repository and its existing instructions before choosing paths, dependencies or commands. Keep one coherent stack and explain changes to the proposed architecture.
- Plan a vertical slice that accepts a real input and produces the useful output described below. Persist only the state the prompt calls for; respect memory-only and upstream-managed workflows. Use fixtures only when they are clearly labelled.
- After scaffolding, document the actual install, development, check and build commands in README and keep them synchronized with the package or project manifest. Do not report commands as successful unless they ran.
- Work in small steps. At handoff, list implemented flows, checks actually performed, remaining blockers, and any credentials or provider setup the owner must supply.
- Do not publish, spend money, contact customers, delete source data or run irreversible migrations without the project owner's authorization.

## Prerequisites
- Runtime and tools: TypeScript, Node, Express, better-sqlite3, a small first-party browser tracker and a durable aggregation worker with an authenticated server-rendered dashboard.
- Before starting: One owned site, HTTPS tracker/intake URLs, private dashboard credentials, a declared event schema, a retention/deletion policy, and synthetic SPA navigation, duplicate, invalid-site and sensitive-URL fixtures.

## Stack and architecture
- TypeScript, Node, Express, better-sqlite3, a small first-party browser tracker and a durable aggregation worker with an authenticated server-rendered dashboard
- Data design: Store Site, EventType, Observation and Aggregate; allowlist event names/properties and discard sensitive URL parameters before they reach logs or database storage.
- Setup: One owned site, HTTPS tracker/intake URLs, private dashboard credentials, a declared event schema, a retention/deletion policy, and synthetic SPA navigation, duplicate, invalid-site and sensitive-URL fixtures

## Security and data integrity
- Treat the browser site ID as public, not a secret credential. Validate registered sites, allowed browser origins and bounded event schemas, with per-site quotas; an Origin header is only one abuse signal. Strip unapproved URL parameters, referrer details and event properties before logs, queues or storage. Deduplicate by site and client event ID within a documented window. Store accepted events and pending aggregation state durably; update aggregates and mark events processed in one transaction so retries cannot count twice. Define event-time/timezone and late-event rules, retention and deletion across raw data and aggregates. Keep dashboard queries scoped to the authenticated site owner and do not infer audited people from event counts.
- Counts are observations rather than audited people or conversions. Cookieless tracking still needs a considered privacy design; no raw fingerprinting or unverifiable legal-compliance promise.
- Keep secrets outside client bundles and exported projects; document what leaves the device and make retention/deletion controls visible.

## Agent implementation rules
- Project rule — domain: Store Site, EventType, Observation and Aggregate; allowlist event names/properties and discard sensitive URL parameters before they reach logs or database storage.
- Project rule — scope and recovery: Counts are observations rather than audited people or conversions. Cookieless tracking still needs a considered privacy design; no raw fingerprinting or unverifiable legal-compliance promise.
- Project rule — acceptance: Submit a referrer containing a token and repeat a page event during SPA navigation; sanitize the referrer and apply a documented navigation-count policy.
- Project rule — delivery: document real setup commands and permissions; do not claim a build, accuracy level, performance result or security certification that has not been demonstrated.

## Optional agent skills and references
- Recommended skill: [web-design-guidelines](https://github.com/vercel-labs/agent-skills/blob/main/skills/web-design-guidelines/SKILL.md) — review keyboard access, focus, validation, error recovery and the readable work/review interface or HTML report. Follow the maintainer's installation instructions and match its requirements to the chosen runtime.
- Recommended skill: [sharp-edges](https://github.com/trailofbits/skills/blob/main/plugins/sharp-edges/skills/sharp-edges/SKILL.md) — review configuration and API defaults against the app-specific invariants and recovery boundaries above; this is not a security certification. Follow the maintainer's installation instructions and match its requirements to the chosen runtime.

Read the linked SKILL.md and its dependencies before adding a skill. Select only the skills matching this project's runtime and task; their documentation does not supply API access, credentials or approval to perform external actions. Pin the reviewed revision where the tool supports it. Follow the chosen agent's documented project-level installation mechanism.

## Distribution ideas
These are optional planning notes. Obtain the owner's approval before publishing or contacting anyone.
- Demonstrate this working slice using synthetic or explicitly authorized non-sensitive examples: Collect minimal pageviews and named events from one owned site, aggregate common dimensions and provide a private dashboard plus CSV export.
- Share a synthetic example export and the acceptance walkthrough; keep real customer, health, financial and source data private: Submit a referrer containing a token and repeat a page event during SPA navigation; sanitize the referrer and apply a documented navigation-count policy.
- State the limits before asking someone to replace their existing tool: Counts are observations rather than audited people or conversions. Cookieless tracking still needs a considered privacy design; no raw fingerprinting or unverifiable legal-compliance promise.

## Engineering roadmap
1. Phase 1 — Pin the working slice and create its example input: Collect minimal pageviews and named events from one owned site, aggregate common dimensions and provide a private dashboard plus CSV export. Confirm setup: One owned site, HTTPS tracker/intake URLs, private dashboard credentials, a declared event schema, a retention/deletion policy, and synthetic SPA navigation, duplicate, invalid-site and sensitive-URL fixtures.
2. Phase 2 — Implement persistence and write-time invariants before decorating the UI: Store Site, EventType, Observation and Aggregate; allowlist event names/properties and discard sensitive URL parameters before they reach logs or database storage.
3. Phase 3 — Connect the working view to real saved state. Treat the browser site ID as public, not a secret credential. Validate registered sites, allowed browser origins and bounded event schemas, with per-site quotas; an Origin header is only one abuse signal. Strip unapproved URL parameters, referrer details and event properties before logs, queues or storage. Deduplicate by site and client event ID within a documented window. Store accepted events and pending aggregation state durably; update aggregates and mark events processed in one transaction so retries cannot count twice. Define event-time/timezone and late-event rules, retention and deletion across raw data and aggregates. Keep dashboard queries scoped to the authenticated site owner and do not infer audited people from event counts.
4. Phase 4 — Expose the app-specific limits and recovery path in context: Counts are observations rather than audited people or conversions. Cookieless tracking still needs a considered privacy design; no raw fingerprinting or unverifiable legal-compliance promise.
5. Phase 5 — Walk through this concrete acceptance case and preserve its exported evidence: Submit a referrer containing a token and repeat a page event during SPA navigation; sanitize the referrer and apply a documented navigation-count policy. Finish the README and backup/restore instructions; report unfinished capabilities explicitly.

## Paid-product capabilities outside this build
- managed hosting
- privacy/legal positioning
- bot filtering
- reports
- uptime
- support

## Implementation prompt
Build the following focused alternative to Simple Analytics. Implement the focused workflow below first; the verdict is not evidence of a completed or production-certified build.

WORKING SLICE
Collect minimal pageviews and named events from one owned site, aggregate common dimensions and provide a private dashboard plus CSV export.

SETUP AND ARCHITECTURE
Use TypeScript, Node, Express, better-sqlite3, a small first-party browser tracker and a durable aggregation worker with an authenticated server-rendered dashboard. Prerequisites: One owned site, HTTPS tracker/intake URLs, private dashboard credentials, a declared event schema, a retention/deletion policy, and synthetic SPA navigation, duplicate, invalid-site and sensitive-URL fixtures. Before integrating anything, record actual versions and permissions, plus model files or provider limits only where used, in the README; make unavailable dependencies visible rather than simulating success.

DOMAIN MODEL AND INVARIANTS
Store Site, EventType, Observation and Aggregate; allowlist event names/properties and discard sensitive URL parameters before they reach logs or database storage.

IMPLEMENTATION CONTRACT
Treat the browser site ID as public, not a secret credential. Validate registered sites, allowed browser origins and bounded event schemas, with per-site quotas; an Origin header is only one abuse signal. Strip unapproved URL parameters, referrer details and event properties before logs, queues or storage. Deduplicate by site and client event ID within a documented window. Store accepted events and pending aggregation state durably; update aggregates and mark events processed in one transaction so retries cannot count twice. Define event-time/timezone and late-event rules, retention and deletion across raw data and aggregates. Keep dashboard queries scoped to the authenticated site owner and do not infer audited people from event counts. Provide an input/setup view, the main work view, and a review/export view appropriate to this workflow. Preserve the last saved state if a job or save fails. Include empty, loading, permission-denied, partial and retryable-error states. Log identifiers and error categories without secret values or unnecessary private content.

APP-SPECIFIC BOUNDARY AND RECOVERY
Counts are observations rather than audited people or conversions. Cookieless tracking still needs a considered privacy design; no raw fingerprinting or unverifiable legal-compliance promise.

ACCEPTANCE SCENARIO
Submit a referrer containing a token and repeat a page event during SPA navigation; sanitize the referrer and apply a documented navigation-count policy. Also reopen the app after an interrupted operation, confirm the saved record/export remains inspectable, and document the recovery action. These are implementation acceptance requirements, not a claim that this guide has been tested.

DELIVERY
Deliver a runnable repository with migrations or project-format versioning, a non-sensitive example, environment/permission setup, the exact manual acceptance steps, and a backup/export-and-restore walkthrough. Implement the working slice before optional integrations; list any deferred paid-product capabilities honestly. Do not add capabilities outside the working slice just to resemble the original product.

PROJECT RULES FOR AGENTS.md
Keep the domain invariants above executable at the write boundary. Propose scope changes before adding providers or permissions. Never fabricate source evidence, publish results, identity matches or successful delivery. Preserve user originals and require an explicit confirmation for destructive changes or external publication.

## Completion evidence
Demonstrate the prompt's acceptance scenarios against the scoped workflow. Include setup from a clean checkout and failure recovery. Check persistence across restart and export/restore only for the state the prompt says to store; for memory-only tools, confirm that temporary content is discarded as specified. Record actual results and remaining limitations. A detailed plan alone does not establish a working replacement.
