# Analytics

Analytics reference: requirements, settings, 6 agent tools with full notes, and core events, read from the code.

See which source brings you leads and sales: visits, page views and conversions by search, social, email, ads, AI assistants and other sites, with what each form, popup, affiliate link and waitlist converted. Five plain screens, no setup, nothing leaves your site.

**Beta.** Analytics is in beta: it works, but things may still break. If something breaks, [report it](https://github.com/sundoggs/support/issues/new).

On the store: [Analytics](https://sundo.gs/apps/analytics) in [Analytics and tracking](https://sundo.gs/categories/analytics-and-tracking), [pricing](https://sundo.gs/pricing).

## Price

Free on any number of sites. You need a free account to claim and download it: see the [store page](https://sundo.gs/apps/analytics).

## Requirements

- Cloudflare® plan: Cloudflare free plan
- Works on: Cloudflare Workers; Cloudflare Pages; A site on its own server (VPS or cloud) with DNS on Cloudflare, through a Worker route in front of it (beta, tested on a live server) ([hosts](https://sundo.gs/docs/hosts.md))
- Version: 0.4.10 (needs core 0.23.0 or later; it comes in the same download)
- Runs on the Cloudflare free plan, in the same D1 database as your other site apps. No new bindings, no script on your pages and no account anywhere else.
- It reads what core already captures for free: page views and visit sources are counted as your pages are served (page views run through the site apps, as with link tagging), and each app that reports (forms, popups, links, waitlist, reviews) saves its conversions with the visitor's source. This app adds the reports.
- Privacy: counts per day carry no id, cookie or IP. Where a visitor arrives from is kept for 90 days against a code that changes every day (not their IP) so a later form can be credited. Where your cookie banner asks for consent and the visitor says no, or they opt out or send Do Not Track, their conversions show as "Not tracked". Not legal advice: check your own privacy policy.
- Numbers are approximate: a few percent of counts can be lost when your site's Worker restarts, and bots are filtered with simple checks on the browser's user agent and headers (the free plan has no bot score), so a scraper that pretends to be a browser counts as a visit.
- Cost per visit: no extra requests. Visit counts are added up in memory and saved every 20 seconds, or less often when busy: 1 database row for each page viewed plus 4 for the visit (its source, country, device and their combination), so about 7 rows for a 3-page visit on a quiet site and fewer on a busy one. A visit that arrives from a link, search or ad, where consent allows, also saves a visit note: 4 rows, and 3 more in later days when it is cleaned up. Visit counting stops once the site's logging for the day reaches half of the daily logging budget (default 40,000 rows of the Cloudflare 100,000 free, so 20,000). That half is shared: it counts the visits together with the site's other logging (missing pages, redirect hits, link clicks, popup views, conversions). When it or the Cloudflare free limit is reached counting pauses until midnight UTC and the site is unaffected. On a site with little other logging that is roughly 2,200 three-page visits a day when half of them arrive from a link or search (fewer when other apps log a lot; busier sites save in bigger batches and go further); Settings shows today's budget, and a Workers Paid site can raise it.

## What it adds to the site

- Addresses it answers: none
- Edits pages as they are served: yes
- Has a say when a page is not found: no
- Uses the site's [brand](https://sundo.gs/docs/core.md#brand): no
- [Core](https://sundo.gs/docs/core.md) capabilities it uses: `analytics`
- Database tables (in the site's own D1 database): none

## Agent tools

Analytics adds 6 tools to the site's own [agent connection](https://sundo.gs/docs/agent-connection.md). The short text under each name is what an agent sees in its tool list; the full notes are what `site_tool_help` returns. The [shared rules](https://sundo.gs/docs/core/site-tools.md#shared-rules) for `confirm`, `dry_run` and `on` apply to every tool.

### Read (changes nothing)

#### `analytics_summary`

Start here. Visits, page views, conversions, rate and value for 7, 30 or 90 days against the previous period, top sources, the counted conversions with their worth, and `recommendations` (call `apply` only if the owner agrees). If `period.complete` is false the period is shorter than it says.

Read only: changes nothing.

**Full notes** (what `site_tool_help` returns):

Worth is in cents, including the worth of single forms or popups. `recommendations` ([{id, text, why, apply?: {tool, args}}]) are the same suggestions the admin shows: explain each in a sentence or two and call `apply` only if the owner agrees; one without `apply` is a note (for example the owner has to give you a value). The worth numbers are the owner's, shared with the Tag Manager. `period.trackingSince` is the first day anything was counted: when `period.complete` is false the period is shorter than it says, so never call a rise from a nearly empty previous period growth. filter: at most two keys at once; anything else is ignored. `source`: a channel ("search", "social", "email", "paid", "ai", "referral", "campaign", "direct") or "channel:source" like "search:google" or "ai:chatgpt"; `page`: the page visits started on, like "/blog/hosting"; `country`: a 2-letter code like "DE". Visits and conversions are filtered; page views are not counted by source or country, so they come back null. On a site that was counting before this existed, visits can be filtered only from the day the new visit table started.

| Field | Type | Required | What it is |
|---|---|---|---|
| `range` | `7`, `30`, `90` | no | Days to look back: 7, 30 or 90 (default 30). |
| `filter` | object | no | One slice, as the Overview's filter chips (at most two): `source` a channel or "channel:source" ("search:google"), `page` where visits started, `country` a 2-letter code. Page views come back null. |

#### `analytics_sources`

Where visits and conversions come from: every channel (search, social, email, paid, AI assistants, other sites, direct), the sources inside them, and UTM campaigns. Optionally for one app's conversions.

Read only: changes nothing.

**Full notes** (what `site_tool_help` returns):

filter: at most two keys at once; anything else is ignored. `source`: a channel ("search", "social", "email", "paid", "ai", "referral", "campaign", "direct") or "channel:source" like "search:google" or "ai:chatgpt"; `page`: the page visits started on, like "/blog/hosting"; `country`: a 2-letter code like "DE". Visits and conversions are filtered; page views are not counted by source or country, so they come back null. On a site that was counting before this existed, visits can be filtered only from the day the new visit table started.

| Field | Type | Required | What it is |
|---|---|---|---|
| `range` | `7`, `30`, `90` | no | Days to look back: 7, 30 or 90 (default 30). |
| `app` | string | no | Only conversions of this app id, like forms, popups, links, waitlist. |
| `filter` | object | no | One slice, as the Overview's filter chips (at most two): `source` a channel or "channel:source" ("search:google"), `page` where visits started, `country` a 2-letter code. Page views come back null. |

#### `analytics_pages`

Top pages (views, and visits that started there) with the conversions credited to the page each visit started on. With a filter, views are null.

Read only: changes nothing.

**Full notes** (what `site_tool_help` returns):

/guides and /guides/ are one page; paths are listed without the trailing slash (the admin shows them the way the site writes them: see pagePathsShownWithTrailingSlash). filter: at most two keys at once; anything else is ignored. `source`: a channel ("search", "social", "email", "paid", "ai", "referral", "campaign", "direct") or "channel:source" like "search:google" or "ai:chatgpt"; `page`: the page visits started on, like "/blog/hosting"; `country`: a 2-letter code like "DE". Visits and conversions are filtered; page views are not counted by source or country, so they come back null. On a site that was counting before this existed, visits can be filtered only from the day the new visit table started.

| Field | Type | Required | What it is |
|---|---|---|---|
| `range` | `7`, `30`, `90` | no | Days to look back: 7, 30 or 90 (default 30). |
| `filter` | object | no | One slice, as the Overview's filter chips (at most two): `source` a channel or "channel:source" ("search:google"), `page` where visits started, `country` a 2-letter code. Page views come back null. |

#### `analytics_conversions`

What converted, per app and item (a form, a popup, a link, a waitlist), with its best sources, and the last conversions as short paths (source, page, action). No personal data.

Read only: changes nothing.

**Full notes** (what `site_tool_help` returns):

filter: at most two keys at once; anything else is ignored. `source`: a channel ("search", "social", "email", "paid", "ai", "referral", "campaign", "direct") or "channel:source" like "search:google" or "ai:chatgpt"; `page`: the page visits started on, like "/blog/hosting"; `country`: a 2-letter code like "DE". Visits and conversions are filtered; page views are not counted by source or country, so they come back null. On a site that was counting before this existed, visits can be filtered only from the day the new visit table started.

| Field | Type | Required | What it is |
|---|---|---|---|
| `range` | `7`, `30`, `90` | no | Days to look back: 7, 30 or 90 (default 30). |
| `app` | string | no | Only this app id (forms, popups, links, waitlist, reviews). |
| `item` | string | no | Only this item, like a form's name or a link's slug. |
| `filter` | object | no | One slice, as the Overview's filter chips (at most two): `source` a channel or "channel:source" ("search:google"), `page` where visits started, `country` a 2-letter code. Page views come back null. |

### Change

#### `analytics_purge`

Remove test traffic: delete the conversions (and visit notes only they point to) of one item and/or in a time range (UTC). Needs at least one of item, from, to. The first call previews the counts; cannot be undone. The daily totals of visits and page views keep test visits. DESTRUCTIVE, HIGH RISK: does nothing until the owner agrees and you send "confirm" as the exact text the first answer names.

Changes the site. Destructive: does nothing until it is called again with `confirm`.

**Full notes** (what `site_tool_help` returns):

item is a form's name, a link's slug, optionally with `app`. `from` is included, `to` excluded; a date alone as `to` includes that whole day. There is no delete-everything. Without confirm it only previews and says exactly how many conversions and visit notes would go; show the owner that, then call again with the confirm text. What it cannot remove: the daily totals of visits, page views, countries and devices have no visitor in them, so test visits stay counted there. To keep the owner's own browser out of the numbers from now on, open /?site_analytics_ignore=1 in it.

| Field | Type | Required | What it is |
|---|---|---|---|
| `item` | string | no | The form's name, popup's name or link's slug, as shown in Conversions. |
| `app` | string | no | Only this app's item (forms, popups, links...). |
| `from` | string | no | Start, like 2026-11-01 or 2026-11-01T20:59:00Z (UTC), included. |
| `to` | string | no | End, excluded; a date alone includes that day. |
| `confirm` | string | no | Leave out first: the answer names the text to send. Send it only after the owner agrees. |
| `confirm_token` | string | no | The answer's confirmToken, sent with confirm:true and the same input. |

#### `analytics_settings_save`

Change which conversions count, what each is worth, pages to leave out, and how long conversions are kept. Only set a worth the owner told you; never guess one. PATCH: only the keys you send change.

Changes the site.

**Full notes** (what `site_tool_help` returns):

Send `conversions` as an object keyed by "\<app\>.\<id\>" (see analytics_summary for the list), e.g. {"forms.submit":{"count":true,"worth":40,"items":{"quote":200,"newsletter":2}}}. `worth` is what one conversion of that type is worth in the site's currency (40 = $40) and `items` gives one form, popup or link its own worth; null or "" removes a value. These are the same values the Tag Manager sends to ad tags (tags_values_save changes them too). sendToTags puts the owner's values in the page's code, visible to anyone: switch it on only when the owner agrees. PATCH: everything you don't send keeps its saved value.

| Field | Type | Required | What it is |
|---|---|---|---|
| `conversions` | object | no | A free map keyed by "\<app\>.\<id\>" (see analytics_summary for the ids); each value is {count?, worth?, items?}. Worth is a number the owner gave you. |
| `exclude` | string | no | Paths not to count, one per line; a trailing \* matches everything under it. |
| `retention_days` | integer | no | How long to keep conversions (default 400). |
| `sendToTags` | boolean | no | Send the values to ad tags (true) or hold them back (false). Only with the owner's OK: the values become visible in the page. |
| `currency` | string | no | The currency of the values, a 3-letter code like USD, EUR or GBP (default USD). Shared with the Tag Manager, which sends it with the value. |
| `dry_run` | boolean | no | true: save nothing; answers wouldSave (the full record) and the warnings. |

## Core events

It sends and listens to none.

How events work: [core events](https://sundo.gs/docs/core.md#events).

## Works with your other apps

Connects with no setup, in any install order: [Forms](https://sundo.gs/docs/apps/forms.md), [Links & Redirects](https://sundo.gs/docs/apps/links.md), [Popups](https://sundo.gs/docs/apps/popups.md), [Waitlist](https://sundo.gs/docs/apps/waitlist.md), [Tag Manager](https://sundo.gs/docs/apps/tags.md), [Cookie Consent](https://sundo.gs/docs/apps/consent.md).

---

This page on the web: https://sundo.gs/docs/apps/analytics/
