Quickstart
Count a site in five minutes, with a script tag on any site, or with the package for Next.js or React.
You need a running Chokh and a site in it. If you have neither,
run it first: one docker compose up, one account, one site.
Below, my_site is your site's id and https://analytics.example.com is the
address your install answers on.
The npm packages
@chokh/next,@chokh/reactand@chokh/sdk-nodeare not on npm yet: they are published with Chokh's first release. The script tag works today, on any site.
Add the tracker
Pick your framework once; every example on these pages then follows it.
HTML
<script defer data-site="my_site" src="https://analytics.example.com/a.js"></script>
Next.js
import type { ReactNode } from 'react';
import { Analytics } from '@chokh/next';
export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html lang="en">
<body>
{children}
<Analytics site="my_site" vitals errors />
</body>
</html>
);
}
React
import type { ReactNode } from 'react';
import { ChokhProvider } from '@chokh/react';
export function Root({ children }: { children: ReactNode }) {
return (
<ChokhProvider site="my_site" src="https://analytics.example.com/a.js" vitals errors>
{children}
</ChokhProvider>
);
}
That is the whole of it. The tracker counts the first page and every page
after it, a single page app's route changes included, so there is no
trackPageview to call. On Next.js the tag is one of three files, and the
tracker is served from your own domain; the Next.js page has the
other two.
vitals and errors also load the scripts for Core Web Vitals and
JavaScript errors, which the Health report reads. Leave them off to collect
pageviews alone.
Send an event
HTML
<!-- A click on an element with data-pa-event is an event, with each
data-pa-prop-<name> as a property. -->
<button data-pa-event="signup" data-pa-prop-plan="pro">Sign up</button>
<!-- Or from your own code, once the tag has loaded. -->
<script>
pa('event', 'quiz_start', { quizId: 'q1' });
</script>
Next.js
'use client';
import { useTrack } from '@chokh/next';
export function SignupButton() {
const track = useTrack();
return <button onClick={() => track('signup', { plan: 'pro' })}>Sign up</button>;
}
React
import { useTrack } from '@chokh/react';
export function SignupButton() {
const track = useTrack();
return <button onClick={() => track('signup', { plan: 'pro' })}>Sign up</button>;
}
An event's properties are what the site chooses to say about it, like a plan
or a quiz id, and anybody who can read the site's reports sees them. What is
about a person belongs in identify, which only an account allowed to read
identities sees.
Count what your server knows
An order that was paid, a signup that completed: facts a server is sure of and a page cannot be trusted with. Events from your server sends them with a key.
What is counted, and what is kept
By default the tracker sets no cookie and stores nothing in the browser, and
the collector keeps no full address: it tells visitors apart by the address,
the browser and a salt that changes every day, and stores the address with
its last part zeroed.
A site that signs people in can choose a visitor id kept in the browser and
full addresses instead, as settings of that site. The tracker honours Do Not
Track when the tag carries data-dnt, and sends nothing until consent when it
carries data-consent.