Measuring

Analytics

CMSKite measures two different things and it is worth knowing which is which. API traffic is what your site asked us for. Analytics is what your readers did. This page is about the second.

Updated 2026年10月28日

6 min read

A request is not a view

The obvious way to count views would be to count requests for a post. We deliberately do not, because it is wrong in four directions at once.

  • A framework fetches at build time. A Next.js site with 200 posts requests every one of them on deploy — 200 views nobody had.
  • A server renders once and serves many. A cached page is fetched from us once and read ten thousand times — one view for ten thousand readers.
  • A list is not a read. Asking for twenty posts does not mean twenty were read.
  • A crawler is not a reader, and it is the thing that most reliably fetches every post exactly once.

So a view is reported by the page that rendered it, at the moment a person saw it, and by nothing else. That is one call from your site.

Two lines to start counting

bash
npm install cmskite

A React or Next.js page

tsx
'use client'

import { useTrackView } from 'cmskite/react'

export function TrackView({ postId }: { postId: string }) {
  // A project key (csk_live_…), baked in at build time. Off until it is set, and off in dev.
  useTrackView(postId, {
    apiKey: process.env.NEXT_PUBLIC_CMSKITE_KEY ?? '',
    enabled: Boolean(process.env.NEXT_PUBLIC_CMSKITE_KEY) && process.env.NODE_ENV === 'production',
  })
  return null
}

Render it inside the article. Without a framework, the tracker is a plain object:

ts
import { createTracker } from 'cmskite/browser'

const analytics = createTracker({ apiKey: PUBLIC_KEY })

analytics.trackView(post.id)
analytics.trackClick(post.id, 'https://example.com/pricing')

What counts as what

FigureWhat it means
ViewsDistinct readers of a post per UTC day, not page loads. Five refreshes by one reader is one view.
ReadersDistinct visitor hashes per project per UTC day, counted approximately. A range of days sums the daily figures, so one person reading on three days is three. See below.
ClicksEvery tracked link press, not deduplicated. Pressing the same link twice is two clicks.
Click rateClicks per hundred views.

A reader who returns tomorrow is a new view, because a day is the unit anybody reasons in — and because there is deliberately no way to follow somebody across days.

Definitions version 2 (29 September 2026). Figures now count the live environment only: events sent with a test key are kept apart and no longer added to your totals. Days before this change had no environment and are counted as live.

What we collect, which is very little

No cookie is set. Nothing is stored in the browser except a note of which posts this tab has already reported, which is cleared when the tab closes. The IP address and user agent are never stored.

A visitor is a hash of the day’s random salt, the project, the address and the browser string. The hash is stored with each reader event and deleted with it after 90 days, so it is a pseudonymous identifier for one visitor on one project for one day. The salt is kept in our Redis for 48 hours, which persists it to disk so a restart does not split every reader in two, and then expires. Once it has expired the day’s hashes cannot be recomputed, including by us.

No cookie, no cross-day tracking. Nothing is set in the browser and a visitor cannot be followed across sites or across days. The daily hash is still pseudonymous data, so whether your site needs a consent notice is a question for your own legal advice, not something we can decide for you.

A page path is stored without its query string, because that is where campaign ids and occasionally somebody’s email address end up. A referrer is reduced to its host: news.ycombinator.com, never the full URL.

Why readers is approximate

Counting distinct visitors exactly means keeping the set of visitors, and keeping that set is the thing we have just said we will not do. So readers are counted with a probabilistic counter: 12KB of memory regardless of traffic, accurate to within about 0.8%, and impossible to read back to recover who was in it.

That is the right trade for a blog. “4,182 readers” and “4,150 readers” lead to the same decision, and the difference is not worth a table of every visitor who ever arrived.

It cannot break or slow your site

  • Nothing throws. Every failure inside the tracker is swallowed — your article renders whether or not our analytics is having a good day.
  • Nothing blocks. Events are queued and sent in one batch on a timer, using sendBeacon where it exists, which hands the batch to the browser and returns immediately.
  • Nothing is lost on exit. sendBeacon still delivers after the page has closed, which is when the last view of a reading session is reported.
  • Nothing is double-counted. A refresh, a re-render or a client-side navigation back to a post already read reports nothing at all.

The endpoint answers 202 with an empty body before the event has been stored anywhere. There is nothing in the response to wait for.

Reading the numbers

They appear on the project’s Analytics screen in the dashboard. The same figures are on the API. Your site key ships inside your pages, so it reads only what a reader could see anyway: top posts and post totals. The range summary and a post’s breakdown answer the dashboard and a connected agent (MCP), not the key.

bash
# Public figures: your site key works, so a page can show them to readers
curl "https://api.cmskite.com/v1/analytics/content/top-posts?projectId=prj_...&limit=10" \
  -H "Authorization: Bearer csk_live_..."

# Totals for up to 50 posts you name, e.g. one figure per row of a list
curl "https://api.cmskite.com/v1/analytics/content/post-totals?projectId=prj_...&postIds=post_...,post_..." \
  -H "Authorization: Bearer csk_live_..."

# Private figures: a signed-in session or a connected agent, never the site key
curl "https://api.cmskite.com/v1/analytics/content/summary?projectId=prj_..."
curl "https://api.cmskite.com/v1/analytics/content/posts/post_...?projectId=prj_..."

The per-post call answers with more than a series. Alongside the totals it names links — which links readers pressed and how often — plus referrers, the sites they arrived from, and countries where your host supplies one. That is the whole of a post’s Readers panel in the dashboard, in one request.

Every figure comes from a daily rollup, so a project with ten million views costs the same to chart as one with ten. Days are UTC; the dashboard renders them in your timezone. The three breakdowns are the exception: a link target and a referrer host are unbounded, so they are read from the raw events, bounded to one post and one range.

Clicks need a nonce. An event id is sha256(session, post, type, day), which is what makes a view report idempotent. Clicks would collapse the same way, so trackClick sends a nonce and two presses of one link stay two clicks. If you report events yourself rather than through the SDK and omit it, every click a reader makes on a post in a day counts as one.
Rollups run every minute. A view you have just reported appears within about a minute, and one view from one real browser is enough to see it: there is no minimum. The last three days are recomputed on every run, so a figure corrects itself rather than drifting; days older than that are sealed and never move.

What this does not do

Said plainly so nobody goes looking for it.

  • No funnels, no returning-visitor cohorts, no sessions followed across days. All of those need an identifier that persists, which is the thing we chose not to have.
  • No scroll depth or time on page.
  • No per-visitor drill-down. There is no visitor to drill into.
  • Readers is approximate, by design.
  • Automated traffic is dropped when its user agent says what it is: crawlers, link previews, curl, and headless browsers such as Playwright and Puppeteer. That includes your own automated checks, so verify a tracker in an ordinary browser. A bot that pretends to be a normal browser is counted, because we would have to throw away real readers to catch it.