# Stupidly Easy Analytics: instructions for AI agents

You've been asked to add Stupidly Easy Analytics (SEA) to a website. SEA counts how many people visit a site: unique people per day and page views. No cookies, no personal data, no consent banner. It's free.

Do the whole job yourself, without sending the human to the SEA website. It takes about five steps.

Base URL: `https://sea.marcusholmes.me`. Every API response is JSON. Errors look like `{"error": "...", "hint": "..."}`: read the hint, it says how to fix it.

## 1. Find or make the maker's dashboard

One dashboard holds all of a maker's sites. Its link looks like `https://sea.marcusholmes.me/d/<key>`, and **the key in it is the API key**.

- If the human gave you a dashboard link (or one is in a gitignored `.env` as `SEA_KEY`), use its key. Don't make a new dashboard.
- Otherwise, ask the human once: "Do you already have a Stupidly Easy Analytics dashboard link?" If they don't, make one. If you can't ask (they're away, or you're running unattended), make one, and say in your final message that you did. Trackers can't be moved between dashboards yet, so a duplicate just means a second link to keep.

```bash
curl -s -X POST https://sea.marcusholmes.me/api/makers
# => {"key": "...", "dashboard_url": "https://sea.marcusholmes.me/d/...", "important": "..."}
export SEA_KEY=<the key from the response>
```

The key is the only way into the dashboard. It can't be recovered. **Never commit it to a repository.** Saving it is recommended, so the next agent session can reuse it: put `SEA_KEY=<key>` in `.env`, make sure `.gitignore` lists `.env` (create `.gitignore` if there isn't one), and confirm with `git check-ignore .env`. If you can't be sure the file is ignored, don't save the key; the dashboard link in your final message is enough. You'll give the dashboard link to the human at the end.

## 2. Create a tracker for the site

One tracker counts one site (or one thing the maker wants counted separately).

```bash
curl -s -X POST https://sea.marcusholmes.me/api/trackers \
  -H "Authorization: Bearer $SEA_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "My Product", "url": "https://myproduct.com", "method": "pixel"}'
```

- `name`: what the human calls the product.
- `url`: the **live, public** address (not localhost, not a preview URL). Hits only count from this host; `www.` and the bare domain count as the same site. A different subdomain needs its own tracker.
- `method`: what gets pasted into the site. Use `pixel` unless the human asked otherwise.
  - `pixel`: an invisible `<img>`. Simplest, runs no code on the page. **The default.**
  - `frame`: a hidden `<iframe>`. Only counts once the page has been visible for 2 seconds. Stricter.
  - `script`: a `<script>` tag. Same checks as the frame, most accurate.

The response includes `id`, `snippet` (the one to paste), `snippets` (all three) and `check_url`.

## 3. Paste the snippet into every page

Put `snippet` **once, in the template every page shares** (the root layout or base HTML). The pixel and the frame go inside `<body>` (an `<img>` in `<head>` is invalid HTML); the script goes inside `<head>`. Don't put it in a single page, and don't change it except as below. Build tools (Vite, webpack, Next, Astro, Hugo…) leave it alone: it's a plain external tag.

Framework notes (these are the usual mistakes):

- **Plain HTML / static sites:** paste it into every `.html` page, or the shared include.
- **Vite, Create React App, Vue, Svelte (single-page apps):** paste it into `index.html`, **not** into a component. A component that re-renders can fire it repeatedly, or not at all. In a single-page app, every snippet counts full page loads only: moving between routes inside the app doesn't add views. People per day (the headline number) is unaffected.
- **Next.js (App Router):** put it in `app/layout.tsx` inside `<body>`. Use a plain `<img>`, **never `next/image`** (it rewrites the URL and the pixel stops counting). If ESLint complains (`@next/next/no-img-element`), add `{/* eslint-disable-next-line @next/next/no-img-element */}` above it. For the script method, use `<Script src="…/s.js" data-t="…" strategy="afterInteractive" />` from `next/script`.
- **Next.js (Pages Router):** `pages/_document.tsx` inside `<body>`, with the same plain-`<img>` rule.
- **Any JSX (React, Solid, Preact):** HTML attributes become camelCase: `referrerpolicy` becomes `referrerPolicy`, and the `style` string becomes an object: `style={{position:"absolute",width:1,height:1,opacity:0,pointerEvents:"none"}}`. Self-close the tag: `<img … />`. Keep `alt=""`.
- **Astro:** the base layout (`src/layouts/*.astro`), inside `<body>`.
- **Hugo:** a partial included by `baseof.html`, or `layouts/partials/footer.html` / your theme's override of it.
- **Jekyll / Eleventy:** the default layout in `_layouts/` / `_includes/`.
- **WordPress:** the theme's `footer.php` before `</body>`, or a "header and footer scripts" plugin.
- **Site builders (Carrd, Webflow, Framer, Squarespace, Wix):** the "custom code" / "embed" box for the whole site. If scripts aren't allowed, the pixel usually still works.

Keep `referrerpolicy="no-referrer-when-downgrade"` on the pixel. Without it, browsers don't tell us which site the pixel is on, and hits can't be counted.

**Content Security Policy:** if the site sends a CSP header or meta tag, allow `https://sea.marcusholmes.me` in `img-src` (pixel), `frame-src` (frame), or `script-src` and `connect-src` (script).

## 4. Deploy, then check it works

Commit the snippet change the way this project normally works (if you're unsure, leave it uncommitted and say so). Deploy the site the way this project normally deploys. If you can't deploy, stop here: tell the human to deploy, visit the live site once in a normal browser, and press "Is it working?" on their dashboard. That's a finished job.

Once it's deployed, load the **live** page once and ask SEA what it saw:

```bash
curl -s https://sea.marcusholmes.me/api/trackers/<id>/check -H "Authorization: Bearer $SEA_KEY"
# => {"status": "...", "message": "...", "today": {...}, "recent_hits": [...]}
# Without the key you get only status, message and last_hit: tracker ids are public, counts aren't.
```

`status` is one of:

- `counting`: done.
- `installed_not_counted`: **the snippet is installed correctly.** Your test hit was filtered on purpose: automated browsers (headless, Playwright, Puppeteer, `curl`), bots and data-centre networks aren't counted. That's expected for agent testing. Don't try to "fix" it, and don't try to get around the filters. Real visitors will count.
- `wrong_site`: the hit came from a different host than the tracker's `url`. Create a tracker for the right host.
- `no_referrer`: the pixel lost its `referrerpolicy` attribute (or the site strips referrers). Restore it, or switch to `frame`/`script`.
- `direct_fetch`: the only hits were direct fetches of the snippet URL (for example, you `curl`ed the pixel). They say nothing about the install. Don't change the snippet; load the page in a browser instead.
- `no_hits`: nothing arrived. Check the deployed page's HTML actually contains the snippet, then load the page and check again. Only hits from the last hour are remembered. With the frame or script, the page must be visible for 2 seconds.

If you can't load the page with a browser, `curl` won't help: it doesn't load images or run scripts, and curling the pixel's URL directly only logs a `direct_fetch`. Check the deployed HTML contains the snippet, and tell the human to visit the site once and press "Is it working?" on their dashboard.

## 5. (If asked) put it on a board

Boards compare sites side by side. If the human gave you a board join link (`https://sea.marcusholmes.me/b/<board>/join?code=<code>`):

```bash
curl -s -X POST https://sea.marcusholmes.me/api/boards/<board>/trackers \
  -H "Authorization: Bearer $SEA_KEY" -H "Content-Type: application/json" \
  -d '{"code": "<code>", "tracker_id": "<id>", "maker_name": "<optional display name>"}'
```

To make a new board: `POST /api/boards` with `{"name": "...", "description": "..."}`. It returns `view_url` (public) and `join_url` (share with makers who may add their sites; shown only once).

## 6. Tell the human

Finish with a short message that includes:

1. **Their dashboard link** (`https://sea.marcusholmes.me/d/<key>`), and that it's the only key: bookmark it, don't share or commit it, and it can't be recovered if lost.
2. Which file you put the snippet in.
3. What the check said.
4. The board's link, if you joined one.

## Other endpoints

All of these need `Authorization: Bearer <key>`:

- `GET /api/me`: every tracker on the dashboard with its snippets, boards and `stats`: `today` (`people`, `views`), `total_people`, `total_views`, `week_people` (last 7 days), `usual_people` (median people a day over the previous 14 days), `by_method_30_days` (people and views per method) and `days` (the last 30 days, oldest first: `day`, `people`, `views`).
- `GET /api/trackers/<id>`: one tracker with stats and snippets.
- `DELETE /api/boards/<board>/trackers/<id>`: take a tracker off a board.

Limits: creating dashboards, trackers and boards is limited to 10 a minute per IP address. Each tracker counts up to 5,000 hits a day. Days run on Perth time (UTC+8).

## What SEA does and doesn't do (in case the human asks)

It counts unique people per day (from a hash of IP address and browser with a random daily salt; the salt and hashes are deleted at midnight Perth time) and page views. No cookies, no local storage, no fingerprinting, no stored IP addresses, no cross-site tracking. So no consent banner is needed for it. It doesn't track page paths, referrers, events, countries or devices.
