Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,11 @@ TURNSTILE_SECRET_KEY=
# local dev: `vercel env pull .env.local` after linking.
UPSTASH_REDIS_REST_URL=
UPSTASH_REDIS_REST_TOKEN=

# --- PostHog (counts only: page views by route, waitlist outcomes) ---
# The project key of the EU Cloud project: PostHog, Project settings. Public by
# design (it can only write events), so NEXT_PUBLIC_ is right. Read at build
# time. Leave blank and nothing is loaded or sent. Set it only after the
# privacy notice has been approved. The browser reports to this site's own
# /ingest path, which forwards to the EU cloud, so no host variable exists.
NEXT_PUBLIC_POSTHOG_KEY=
2 changes: 2 additions & 0 deletions app/(site)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AlphaNotice } from '@/components/alpha/AlphaNotice';
import { AnalyticsPageView } from '@/components/alpha/AnalyticsPageView';
import { InPageLinks } from '@/components/alpha/InPageLinks';
import { SiteHeader } from '@/components/alpha/SiteHeader';
import { OpeningSequence, SkipLink } from '@ekdotico/domico/components';
Expand All @@ -18,6 +19,7 @@ export default function SiteLayout({
<>
<SkipLink />
<AlphaNotice />
<AnalyticsPageView />
<OpeningSequence />
<InPageLinks />
<SiteHeader />
Expand Down
28 changes: 22 additions & 6 deletions app/(site)/privacy/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const metadata: Metadata = {
// project can keep without effort, or one the GDPR makes anyway.
//
// Change UPDATED with any change of substance.
const UPDATED = '28 October 2026';
const UPDATED = '21 November 2026';

export default function PrivacyPage() {
return (
Expand Down Expand Up @@ -56,6 +56,18 @@ export default function PrivacyPage() {
www.linkedin.com, without the page you were on. It is kept only once you confirm
your address, and nothing is stored in your browser for it.
</p>
<p>
<em>Counting visits.</em> To learn how many people read this site and whether the
form works, each page you open sends one short message to a measurement service. It
says which page was opened (the home page, this page, the confirmation page, or
another) and carries what your browser sends with any request, such as its name and
version. When you send the form, a second message says whether it worked or failed,
and never the address you entered. Nothing is stored in your browser for this. The
messages of one visit share a random number that lasts only while the page is open,
so there is no identifier that lasts beyond the page, and nothing links one visit to
the next. The service does not receive your network address; it sees only that of
the provider that hosts this site, and works out no location.
</p>
<p>
<em>Who holds it.</em> The Ekdotico team, reachable at{' '}
<a href={`mailto:${SITE_META.contact}`}>{SITE_META.contact}</a>.
Expand All @@ -65,14 +77,17 @@ export default function PrivacyPage() {
given when you send the form and again when you open the confirmation link. You can
withdraw it at any time through the unsubscribe link in any of our emails. For the
spam check and for recording where you signed up from, our legitimate interest in
keeping the form working and in knowing which posts reach people. You can object to
either by writing to us.
keeping the form working and in knowing which posts reach people. For counting
visits, our legitimate interest in knowing whether the site and its form work. You
can object to any of these by writing to us.
</p>
<p>
<em>Who else handles it.</em> Service providers who process it for us and on our
instructions: an email service in the European Union, which stores the waitlist,
sends its emails, and records when and from which network address you confirmed, as
evidence of your consent; the provider that hosts this site; and a spam-check
evidence of your consent; the provider that hosts this site; a measurement service
in the European Union, which receives the messages described under
&quot;Counting visits&quot; through this site&apos;s own address; and a spam-check
service, which looks at your browser and network address to tell a person from a
program. Where any of them may process data outside the European Union, safeguards
recognised by the GDPR, such as standard contractual clauses, apply. You can ask us
Expand All @@ -81,8 +96,9 @@ export default function PrivacyPage() {
<p>
<em>How long.</em> Your address is kept until you unsubscribe or ask us to delete
it, and no longer than the waitlist is needed for news of the opening; the testing list
closes when testing ends, or with the waitlist. Records used to stop the form being
misused are short-lived and deleted automatically.
closes when testing ends, or with the waitlist. Records used to stop the form or the
counting being misused are short-lived and deleted automatically. The counts of visits are kept for
one year and then deleted.
</p>
<p>
<em>Cookies.</em> This site sets no advertising or analytics cookies. Your browser
Expand Down
10 changes: 10 additions & 0 deletions app/ingest/[...path]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { forward } from '@/lib/analytics-proxy';
import { consumeIngest } from '@/lib/rate-limit';

// The path the browser reports to; see lib/analytics-proxy.ts. POST only: the
// library sends its events as one POST to /ingest/e/.
type Context = { params: Promise<{ path: string[] }> };

export async function POST(request: Request, { params }: Context) {
return forward(request, (await params).path, consumeIngest);
}
15 changes: 15 additions & 0 deletions components/alpha/AnalyticsPageView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use client';

import { usePathname } from 'next/navigation';
import { useEffect } from 'react';
import { capture, routePattern } from '@/lib/analytics';

// Counts a visit as the pattern of its route. Renders nothing, and does nothing
// until NEXT_PUBLIC_POSTHOG_KEY is set (lib/analytics.ts).
export function AnalyticsPageView() {
const pathname = usePathname();
useEffect(() => {
capture({ name: 'page_view', props: { route: routePattern(pathname) } });
}, [pathname]);
return null;
}
6 changes: 6 additions & 0 deletions components/alpha/WaitlistForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { type FormEvent, useActionState, useEffect, useId, useRef, useState } fr
import { Button, Checkbox, FormFault, TextField, Tooltip } from '@ekdotico/domico/components';
import { InfoIcon } from '@ekdotico/domico/icons';
import { submitWaitlist, type WaitlistState } from '@/app/(site)/actions';
import { capture, outcomeOf } from '@/lib/analytics';
import { ATTRIBUTION_FIELDS, cleanAttribution, referrerHost, UTM_PARAMS } from '@/lib/attribution';
import { TURNSTILE_ACTION, TURNSTILE_SCRIPT, turnstileSiteKey } from '@/lib/turnstile';

Expand Down Expand Up @@ -82,6 +83,11 @@ const TESTING_HINT =
export function WaitlistForm({ headingLevel = 2 }: { headingLevel?: 2 | 3 }) {
const [state, formAction] = useActionState(submitWaitlist, null);

// Counts how a submission ended: one of five names, never the address.
useEffect(() => {
if (state) capture({ name: 'waitlist_submit', props: { outcome: outcomeOf(state) } });
}, [state]);

if (state?.status === 'ok') {
return (
<div className="waitlist">
Expand Down
75 changes: 75 additions & 0 deletions lib/analytics-browser.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// @vitest-environment happy-dom
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';

const SENTINEL_ADDRESS = 'reader-SENTINEL@example.org';
const SENTINEL_TOKEN = 'turnstile-SENTINEL-0xABC';

afterAll(() => {
vi.unstubAllEnvs();
vi.unstubAllGlobals();
});

// The real library, a made-up key, and every network path replaced, so nothing leaves the test.
async function run(): Promise<string[]> {
vi.stubEnv('NEXT_PUBLIC_POSTHOG_KEY', 'phc_test_key_not_real');
const bodies: string[] = [];
const sink = vi.fn(async (_url: unknown, init?: { body?: unknown }) => {
bodies.push(String(init?.body ?? ''));
return new Response('{"status":1}', { status: 200 });
});
vi.stubGlobal('fetch', sink);
window.fetch = sink as unknown as typeof window.fetch;
Object.defineProperty(navigator, 'sendBeacon', { value: (_: string, d: unknown) => (bodies.push(String(d)), true), configurable: true });

// The library sends by XMLHttpRequest unless told otherwise; record that too.
class RecordingXhr {
status = 200;
readyState = 4;
responseText = '{"status":1}';
onreadystatechange: (() => void) | null = null;
open() {}
setRequestHeader() {}
send(body?: unknown) {
bodies.push(String(body ?? ''));
queueMicrotask(() => this.onreadystatechange?.());
}
}
vi.stubGlobal('XMLHttpRequest', RecordingXhr);
window.XMLHttpRequest = RecordingXhr as never;

const { default: posthog } = await import('posthog-js');
const { buildConfig, outcomeOf } = await import('./analytics');
posthog.init('phc_test_key_not_real', { ...buildConfig(), disable_compression: true, request_batching: false, opt_out_useragent_filter: true });
// A submission whose result carries what must never be sent.
const state = { status: 'refused', message: SENTINEL_ADDRESS, email: SENTINEL_ADDRESS, token: SENTINEL_TOKEN } as never;
posthog.capture('waitlist_submit', { outcome: outcomeOf(state), email: SENTINEL_ADDRESS });
posthog.capture('$autocapture', { $el_text: SENTINEL_ADDRESS });
await new Promise((r) => setTimeout(r, 300));
return bodies;
}

describe('the browser, with analytics on', () => {
let bodies: string[];
// One session for both tests: the library initialises once per page.
beforeAll(async () => {
bodies = await run();
});

// Rule 23: the privacy notice says no analytics cookies, and it stays true.
it('writes no ph_ cookie and no ph_ key to localStorage or sessionStorage', () => {
expect(document.cookie).not.toMatch(/ph_/);
for (const store of [localStorage, sessionStorage]) {
expect(Object.keys(store).filter((k) => /ph_|posthog/i.test(k))).toEqual([]);
}
});

// Rule 24: no address and no Turnstile token in anything sent.
it('sends no address and no spam-check token in any request', () => {
const all = bodies.join('\n');
// The permitted event did go out, so an empty body cannot pass this test.
expect(all).toContain('waitlist_submit');
expect(all).toContain('"outcome":"error"');
expect(all).not.toContain('SENTINEL');
expect(all).not.toContain('$autocapture');
});
});
88 changes: 88 additions & 0 deletions lib/analytics-capture.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// @vitest-environment happy-dom
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';
import { ALLOWED_SEGMENTS } from './analytics-proxy';

// The lazy path as the site runs it: capture() fetches posthog-js after the
// page has loaded and starts it with buildConfig() as it is, compression and
// batching included. Every network path is replaced, so nothing leaves the test.
const requests: { url: string; via: string }[] = [];
const idb = { open: vi.fn(), deleteDatabase: vi.fn(), databases: vi.fn(async () => []) };

beforeAll(async () => {
vi.stubEnv('NEXT_PUBLIC_POSTHOG_KEY', 'phc_test_key_not_real');
const sink = vi.fn(async (url: unknown) => {
requests.push({ url: String(url), via: 'fetch' });
return new Response('{"status":1}', { status: 200 });
});
vi.stubGlobal('fetch', sink);
window.fetch = sink as unknown as typeof window.fetch;
class RecordingXhr {
status = 200;
readyState = 4;
responseText = '{"status":1}';
onreadystatechange: (() => void) | null = null;
private url = '';
open(_method: string, url: string) {
this.url = url;
}
setRequestHeader() {}
send() {
requests.push({ url: this.url, via: 'xhr' });
queueMicrotask(() => this.onreadystatechange?.());
}
}
vi.stubGlobal('XMLHttpRequest', RecordingXhr);
window.XMLHttpRequest = RecordingXhr as never;
Object.defineProperty(navigator, 'sendBeacon', {
value: (url: string) => (requests.push({ url, via: 'beacon' }), true),
configurable: true,
});

// The library drops events from a browser it takes for a bot: happy-dom
// reports itself as automated (navigator.webdriver) and by its own agent.
Object.defineProperty(navigator, 'webdriver', { value: false, configurable: true });
Object.defineProperty(navigator, 'userAgent', {
value: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36',
configurable: true,
});
// happy-dom has no IndexedDB: a stub that records being opened proves the
// library never reaches for it, where an absent API would prove nothing.
vi.stubGlobal('indexedDB', idb);
window.indexedDB = idb as never;

const { capture } = await import('./analytics');
capture({ name: 'page_view', props: { route: '/' } });
capture({ name: 'waitlist_submit', props: { outcome: 'ok' } });
// posthog-js is fetched after the window's load event, then flushes on its own timer.
await new Promise((r) => setTimeout(r, 4000));
}, 15000);

afterAll(() => {
vi.unstubAllEnvs();
vi.unstubAllGlobals();
});

describe('capture(), the lazy path, with the production configuration', () => {
// The list ALLOWED_SEGMENTS is taken from this: a library update that calls
// anywhere else fails here, and the forward would have answered it 404.
it('calls the site\'s own /ingest/e/ and nothing else, and the forward admits exactly that', () => {
expect(requests.length).toBeGreaterThan(0);
const paths = new Set(requests.map(({ url }) => new URL(url, 'https://alpha.ekdoti.co').pathname));
expect([...paths]).toEqual(['/ingest/e/']);
expect([...ALLOWED_SEGMENTS]).toEqual(['e']);
});

// Rule 23, with the storage the first test left out.
it('opens no IndexedDB database, and sets no ph_ cookie or storage key', async () => {
expect(idb.open).not.toHaveBeenCalled();
expect(idb.deleteDatabase).not.toHaveBeenCalled();
expect(document.cookie).not.toMatch(/ph_/);
expect(Object.keys(localStorage).filter((k) => /ph_|posthog/i.test(k))).toEqual([]);
expect(Object.keys(sessionStorage).filter((k) => /ph_|posthog/i.test(k))).toEqual([]);
});

it('loads nothing from the assets host, so the forward need not admit it', () => {
const assets = requests.filter(({ url }) => /\/ingest\/(static|array)\//.test(url));
expect(assets).toEqual([]);
});
});
Loading