@domandigital/create-site 0.10.0 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @domandigital/create-site
2
2
 
3
+ ## 0.11.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 6890c34: A new site installs `@domandigital/craft@^0.23.0`, so its copy gate catches the parallel gerund ("renting X, not running Y") and reports the new `trailing-contrast` tell (DOM-1358).
8
+
9
+ ## 0.11.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 5aae7a3: Cloudflare Web Analytics rule (DOM-1060). The cookie banner gains a settings view with a Visit statistics switch, on by default and kept apart from the measurement choice. The consent record moves to v2 with a `statistics` field; v1 records still read, with statistics on. A new `<WebAnalytics />` component loads the manual Cloudflare beacon for every visitor unless statistics is off, with the token in `site.facts.ts` (`webAnalytics.token`) and `launch:check` failing until it is set. The privacy and cookie pages carry the shared notice wording.
14
+
3
15
  ## 0.10.0
4
16
 
5
17
  ### Minor Changes
package/README.md CHANGED
@@ -36,7 +36,7 @@ it is copied, which is the failure this exists to avoid.
36
36
  | `components/JsonLd`, `components/DesignerCredit` | The JSON-LD script, and the credit: "Website by Doman Digital", linking to the homepage, `rel="nofollow"` |
37
37
  | `/press`, `/resources` | A press page built from the data files, and a noindex home for the site's linkable assets |
38
38
  | `/privacy`, `/cookies`, `/terms`, `/accessibility` | The legal pages from dd-base (Doman-Digital/dd-library), reading the `legal` block of `site.facts.ts`. A null fact is left off the page, never shown as a placeholder |
39
- | `components/CookieBanner`, `lib/consent.ts`, `lib/legal.ts` | The cookie banner (necessary only, or measurement as well, with equal weight), `getConsent()` for anything that sets a non-essential cookie, `openCookieSettings()` to change the choice, and the legal facts with defaults |
39
+ | `components/CookieBanner`, `components/WebAnalytics`, `lib/consent.ts`, `lib/web-analytics.ts`, `lib/legal.ts` | The cookie banner with a settings view (necessary only, or measurement as well, with equal weight), and a Visit statistics switch that is on by default and kept apart from them. `getConsent()` for anything that sets a non-essential cookie, `getStatistics()` and `<WebAnalytics />` for the Cloudflare Web Analytics beacon, which loads for every visitor unless they switch Visit statistics off. `openCookieSettings()` to change the choice, and the legal facts with defaults. The token goes in `site.facts.ts`. The rule is `docs/web-analytics.md` in claude-kit |
40
40
  | `tests/seo/*`, `tests/house.test.ts` | Route coverage, the redirect gate, JSON-LD integrity, the redirect wiring, and the rule that contact details live only in the facts file |
41
41
  | `docs/HOUSE.md` | The house rules, imported by `CLAUDE.md` (created if missing, otherwise one import line is added) |
42
42
  | `docs/DIRECTION.md`, `docs/seo-launch-checklist.md`, `docs/seo-baseline.md` | The site's decision and blocked registers, the listings to claim for its sector, and the launch, 90-day, 6-month and 12-month baseline |
package/dist/cli.js CHANGED
@@ -449,6 +449,7 @@ function layoutFor(project) {
449
449
  { template: "shared/tests/seo/graph.test.ts", dest: "tests/seo/graph.test.ts" },
450
450
  { template: "shared/tests/house.test.ts", dest: "tests/house.test.ts" },
451
451
  { template: "shared/lib/consent.ts", dest: `${base}lib/consent.ts` },
452
+ { template: "shared/lib/web-analytics.ts", dest: `${base}lib/web-analytics.ts` },
452
453
  { template: "shared/lib/legal.ts", dest: `${base}lib/legal.ts` },
453
454
  { template: "shared/docs/site-programme.md", dest: "docs/site-programme.md" },
454
455
  ...GATES.map((g) => ({ template: `shared/scripts/gates/${g}`, dest: `scripts/gates/${g}` }))
@@ -462,6 +463,7 @@ function layoutFor(project) {
462
463
  "page-graph": `${base}lib/graph/page-graph.ts`,
463
464
  "routes-on-disk": "tests/seo/routes-on-disk.ts",
464
465
  consent: `${base}lib/consent.ts`,
466
+ "web-analytics": `${base}lib/web-analytics.ts`,
465
467
  legal: `${base}lib/legal.ts`
466
468
  };
467
469
  if (project.configFile) siteKeys["framework-config"] = project.configFile;
@@ -483,6 +485,7 @@ function layoutFor(project) {
483
485
  { template: "next/app/press/page.tsx", dest: `${project.routesDir}/press/page.tsx` },
484
486
  { template: "next/app/resources/page.tsx", dest: `${project.routesDir}/resources/page.tsx` },
485
487
  { template: "next/components/CookieBanner.tsx", dest: `${base}components/CookieBanner.tsx` },
488
+ { template: "next/components/WebAnalytics.tsx", dest: `${base}components/WebAnalytics.tsx` },
486
489
  ...legalPages
487
490
  ]
488
491
  };
@@ -499,6 +502,7 @@ function layoutFor(project) {
499
502
  { template: "astro/pages/press.astro", dest: "src/pages/press.astro" },
500
503
  { template: "astro/pages/resources/index.astro", dest: "src/pages/resources/index.astro" },
501
504
  { template: "astro/components/CookieBanner.astro", dest: "src/components/CookieBanner.astro" },
505
+ { template: "astro/components/WebAnalytics.astro", dest: "src/components/WebAnalytics.astro" },
502
506
  ...["privacy", "cookies", "terms", "accessibility"].map((page) => ({ template: `astro/pages/${page}.astro`, dest: `src/pages/${page}.astro` }))
503
507
  ]
504
508
  };
@@ -665,6 +669,10 @@ export const facts: SiteFacts = {
665
669
  accessibilityIssues: [],
666
670
  reviewedOn: null,
667
671
  },
672
+ // The site's Cloudflare Web Analytics token (a public id). Add the site in
673
+ // Cloudflare's Web Analytics with the manual setup, never automatic setup.
674
+ // launch:check fails until it is set.
675
+ webAnalytics: { token: null },
668
676
  };
669
677
  `;
670
678
  }
@@ -788,7 +796,7 @@ var HOUSE_DEPENDENCIES = {
788
796
  "@domandigital/seo": "^0.3.0"
789
797
  };
790
798
  var HOUSE_DEV_DEPENDENCIES = {
791
- "@domandigital/craft": "^0.22.0",
799
+ "@domandigital/craft": "^0.23.0",
792
800
  "@types/node": "^22.0.0",
793
801
  vitest: "^4.1.11",
794
802
  // scripts/gates/measure.mjs renders the pages at every viewport, phone first,
@@ -1354,7 +1362,8 @@ ${work.map((w) => ` ${w}`).join("\n")}`);
1354
1362
  "Next:",
1355
1363
  " 1. Fill in site.facts.ts: contact details, hours, accreditations, profiles. Unknown stays null.",
1356
1364
  " 2. Put <DesignerCredit /> and links to /privacy, /cookies, /terms and /accessibility in the footer,",
1357
- " <CookieBanner /> once in the root layout, and <JsonLd graph={buildPageGraph(...)} /> on every page.",
1365
+ " <CookieBanner /> and <WebAnalytics /> once in the root layout, and <JsonLd graph={buildPageGraph(...)} /> on every page.",
1366
+ " Put the site's Cloudflare Web Analytics token in site.facts.ts (webAnalytics.token); launch:check fails until it is set.",
1358
1367
  " Fill in legal in site.facts.ts and have the client confirm the legal pages match what the business does.",
1359
1368
  " 3. Work through docs/seo-launch-checklist.md.",
1360
1369
  ` 4. ${pm} seo:check now, and ${pm} launch:check before go-live.`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domandigital/create-site",
3
- "version": "0.10.0",
3
+ "version": "0.11.1",
4
4
  "private": false,
5
5
  "description": "The first thing that runs on a new Doman Digital client site: installs the house packages and writes the per-site files they read (the facts file, route policy, backlink register, redirects, JSON-LD, the designer credit, house docs and the SEO checks), so every build starts on the same foundation and stays upgradeable by bumping packages.",
6
6
  "license": "Apache-2.0",
@@ -41,7 +41,7 @@
41
41
  "tsup": "^8.3.5",
42
42
  "typescript": "^5.6.3",
43
43
  "vitest": "^4.0.0",
44
- "@domandigital/craft": "^0.22.0",
44
+ "@domandigital/craft": "^0.23.0",
45
45
  "@domandigital/graph": "^0.7.0",
46
46
  "@domandigital/seo": "^0.3.1"
47
47
  },
@@ -1,12 +1,17 @@
1
1
  ---
2
- // The cookie banner. Written by @domandigital/create-site, from the dd-base
3
- // banner (Doman-Digital/dd-library). Unstyled: style it with the site's own
4
- // classes. Put <CookieBanner /> once in the base layout; launch:check fails
5
- // until it is placed.
2
+ // The cookie banner and its settings. Written by @domandigital/create-site,
3
+ // from the dd-base banner (Doman-Digital/dd-library). Unstyled: style it with
4
+ // the site's own classes. Put <CookieBanner /> once in the base layout;
5
+ // launch:check fails until it is placed.
6
6
  //
7
7
  // Hidden until the script finds no stored choice, so a returning visitor
8
- // never sees it flash. The two buttons carry equal weight: refusing must be
9
- // as easy as accepting. Any element with data-cookie-settings brings it back.
8
+ // never sees it flash. Necessary only and Accept measurement carry equal
9
+ // weight: refusing must be as easy as accepting. They answer the
10
+ // consent-based tools only. Visit statistics (Cloudflare Web Analytics) is a
11
+ // separate switch in Settings, on until the visitor switches it off, and
12
+ // neither button changes it. Any element with data-cookie-settings, and the
13
+ // #cookie-settings address, opens the settings. Rule: docs/web-analytics.md
14
+ // in claude-kit.
10
15
  interface Props {
11
16
  class?: string;
12
17
  }
@@ -17,26 +22,69 @@ const { class: className } = Astro.props;
17
22
  <div class={className} role="region" aria-label="Cookie choices" data-cookie-banner hidden>
18
23
  <p>
19
24
  We use cookies the site needs to work. With your permission we also use measurement cookies to see how the site is
20
- used. <a href="/cookies">Cookie policy</a>
25
+ used. Visit statistics run without cookies and you can switch them off in settings. <a href="/cookies">Cookie policy</a>
21
26
  </p>
27
+ <button type="button" data-cookie-choice="settings">Settings</button>
22
28
  <button type="button" data-cookie-choice="necessary">Necessary only</button>
23
29
  <button type="button" data-cookie-choice="measurement">Accept measurement</button>
24
30
  </div>
25
31
 
32
+ <div class={className} role="region" aria-label="Cookie settings" data-cookie-panel hidden>
33
+ <h2>Cookie settings</h2>
34
+ <p>Strictly necessary cookies are always on. They keep the site working and remember these choices.</p>
35
+ <label>
36
+ <input type="checkbox" role="switch" data-cookie-switch="statistics" checked />
37
+ Visit statistics
38
+ </label>
39
+ <p>Counts visits without cookies, to show which pages people use and how fast they load. Used only to improve the site. On unless you switch it off.</p>
40
+ <label>
41
+ <input type="checkbox" role="switch" data-cookie-switch="measurement" />
42
+ Measurement cookies
43
+ </label>
44
+ <p>Optional cookies that show us in more detail how the site is used. Off unless you switch them on.</p>
45
+ <button type="button" data-cookie-panel-action="cancel">Cancel</button>
46
+ <button type="button" data-cookie-panel-action="save">Save choices</button>
47
+ </div>
48
+
26
49
  <script>
27
- import { SETTINGS_EVENT, getConsent, setConsent } from "~site/consent";
50
+ import { SETTINGS_EVENT, getConsent, getStatistics, setConsent } from "~site/consent";
28
51
 
29
52
  const banner = document.querySelector<HTMLElement>("[data-cookie-banner]");
30
- if (banner) {
31
- banner.hidden = getConsent() !== null;
53
+ const panel = document.querySelector<HTMLElement>("[data-cookie-panel]");
54
+ if (banner && panel) {
55
+ const statistics = panel.querySelector<HTMLInputElement>('[data-cookie-switch="statistics"]')!;
56
+ const measurement = panel.querySelector<HTMLInputElement>('[data-cookie-switch="measurement"]')!;
57
+
58
+ const showBannerIfUndecided = () => {
59
+ panel.hidden = true;
60
+ banner.hidden = getConsent() !== null;
61
+ };
62
+ const openSettings = () => {
63
+ statistics.checked = getStatistics();
64
+ measurement.checked = getConsent()?.measurement ?? false;
65
+ banner.hidden = true;
66
+ panel.hidden = false;
67
+ };
68
+
69
+ if (window.location.hash === "#cookie-settings") openSettings();
70
+ else showBannerIfUndecided();
71
+
32
72
  banner.querySelectorAll<HTMLButtonElement>("[data-cookie-choice]").forEach((button) => {
33
73
  button.addEventListener("click", () => {
34
- setConsent(button.dataset.cookieChoice === "measurement");
74
+ const choice = button.dataset.cookieChoice;
75
+ if (choice === "settings") return openSettings();
76
+ setConsent(choice === "measurement");
35
77
  banner.hidden = true;
36
78
  });
37
79
  });
38
- window.addEventListener(SETTINGS_EVENT, () => {
39
- banner.hidden = false;
80
+ panel.querySelector('[data-cookie-panel-action="save"]')?.addEventListener("click", () => {
81
+ setConsent(measurement.checked, statistics.checked);
82
+ panel.hidden = true;
83
+ });
84
+ panel.querySelector('[data-cookie-panel-action="cancel"]')?.addEventListener("click", showBannerIfUndecided);
85
+ window.addEventListener(SETTINGS_EVENT, openSettings);
86
+ window.addEventListener("hashchange", () => {
87
+ if (window.location.hash === "#cookie-settings") openSettings();
40
88
  });
41
89
  }
42
90
  </script>
@@ -0,0 +1,17 @@
1
+ ---
2
+ // Cloudflare Web Analytics for every visitor, from the first page, unless they
3
+ // have switched Visit statistics off in the cookie settings. Not behind the
4
+ // banner's buttons. Put <WebAnalytics /> once in the base layout; launch:check
5
+ // fails until it is placed and the site's token is in site.facts.ts. Written by
6
+ // @domandigital/create-site. Rule: docs/web-analytics.md in claude-kit.
7
+ //
8
+ // A page per navigation, so the beacon needs no single-page option. A site that
9
+ // adds Astro view transitions passes { spa: true } to startWebAnalytics below.
10
+ ---
11
+
12
+ <script>
13
+ import { facts } from "~site/facts";
14
+ import { startWebAnalytics } from "~site/web-analytics";
15
+
16
+ startWebAnalytics(facts.webAnalytics?.token);
17
+ </script>
@@ -42,9 +42,25 @@ const thirdParties = legal.processors.filter((p) => p.setsCookies);
42
42
  choice. These do not need your consent.
43
43
  </p>
44
44
  <p>
45
- <strong>Measurement.</strong> Off until you choose "Accept measurement". They count visits and where they come
46
- from.
45
+ <strong>Visit statistics.</strong> On by default. We count visits with Cloudflare Web Analytics, which sets no
46
+ cookies and stores nothing on your device. You can switch it off in <a href="#cookie-settings" data-cookie-settings>cookie settings</a>.
47
47
  </p>
48
+ <p>
49
+ <strong>Measurement.</strong> Off until you choose "Accept measurement". They count visits and where
50
+ they come from.
51
+ </p>
52
+ <dl>
53
+ <dt>Name</dt>
54
+ <dd>Cloudflare Web Analytics</dd>
55
+ <dt>Purpose</dt>
56
+ <dd>Visit statistics</dd>
57
+ <dt>Storage</dt>
58
+ <dd>None (no cookie or local storage)</dd>
59
+ <dt>Default</dt>
60
+ <dd>
61
+ On. Switch off in <a href="#cookie-settings" data-cookie-settings>cookie settings</a>.
62
+ </dd>
63
+ </dl>
48
64
  </section>
49
65
 
50
66
  {thirdParties.length > 0 && (
@@ -66,7 +82,12 @@ const thirdParties = legal.processors.filter((p) => p.setsCookies);
66
82
  <script>
67
83
  import { openCookieSettings } from "~site/consent";
68
84
 
69
- document.querySelectorAll("[data-cookie-settings]").forEach((el) => el.addEventListener("click", openCookieSettings));
85
+ document.querySelectorAll("[data-cookie-settings]").forEach((el) =>
86
+ el.addEventListener("click", (event) => {
87
+ event.preventDefault();
88
+ openCookieSettings();
89
+ }),
90
+ );
70
91
  </script>
71
92
  </body>
72
93
  </html>
@@ -3,7 +3,8 @@
3
3
  // (Doman-Digital/dd-library), reading every fact from site.facts.ts. A fact
4
4
  // that is null is left out, never filled with a placeholder; launch:check
5
5
  // fails until the ones every site needs are set. A whole document, because a
6
- // fresh Astro site may have no layout yet: move it into yours.
6
+ // fresh Astro site may have no layout yet: move it into yours. The settings
7
+ // link opens the cookie banner's settings, so the layout needs <CookieBanner />.
7
8
  // Written by @domandigital/create-site.
8
9
  import { isRouteIndexable } from "@domandigital/seo";
9
10
  import JsonLd from "~site/components/JsonLd.astro";
@@ -41,8 +42,9 @@ const indexable = isRouteIndexable(policy, "/privacy");
41
42
  <h2>What we collect</h2>
42
43
  <p>
43
44
  When you contact us we keep what you send: your name, how to reach you and your message. When you use the site,
44
- the server records technical details such as your IP address and browser to keep it running and secure. With
45
- your permission, and only then, we also measure how the site is used.
45
+ the server records technical details such as your IP address and browser to keep it running and secure. We
46
+ count visits without cookies, as set out below. With your permission, and only then, we also use measurement
47
+ cookies to see in more detail how the site is used.
46
48
  </p>
47
49
  </section>
48
50
 
@@ -50,11 +52,26 @@ const indexable = isRouteIndexable(policy, "/privacy");
50
52
  <h2>Why we are allowed to</h2>
51
53
  <ul>
52
54
  <li>Answering you and doing the work you ask for: taking steps towards a contract, or a contract, Article 6(1)(b).</li>
55
+ <li>Visit statistics: our legitimate interests, Article 6(1)(f). They are on until you switch them off.</li>
53
56
  <li>Measurement cookies: your consent, Article 6(1)(a). They are off until you accept them.</li>
54
57
  <li>Keeping the site running and secure: our legitimate interests, Article 6(1)(f).</li>
55
58
  </ul>
56
59
  </section>
57
60
 
61
+ <section>
62
+ <h2>Analytics</h2>
63
+ <p>
64
+ <strong>Visit statistics (Cloudflare Web Analytics).</strong> We count visits to see which pages people use,
65
+ where they arrive from, and how quickly pages load, so we can improve the site. Cloudflare runs this for us as
66
+ our processor. It sets no cookies and stores nothing on your device. It uses the page address, the referring
67
+ page, your browser and device type, your country, and page timings, and it doesn't build a profile of you
68
+ or use the data for advertising. Cloudflare keeps these statistics for up to six months, and we keep daily
69
+ totals. The law allows this without asking first, as long as you can say no: switch off
70
+ <strong>Visit statistics</strong> in <a href="#cookie-settings" data-cookie-settings>cookie settings</a> and we'll stop. Our lawful basis is our
71
+ legitimate interest in understanding and improving the site.
72
+ </p>
73
+ </section>
74
+
58
75
  {legal.processors.length > 0 && (
59
76
  <section>
60
77
  <h2>Who we share it with</h2>
@@ -86,5 +103,15 @@ const indexable = isRouteIndexable(policy, "/privacy");
86
103
  </p>
87
104
  </section>
88
105
  </main>
106
+ <script>
107
+ import { openCookieSettings } from "~site/consent";
108
+
109
+ document.querySelectorAll("[data-cookie-settings]").forEach((el) =>
110
+ el.addEventListener("click", (event) => {
111
+ event.preventDefault();
112
+ openCookieSettings();
113
+ }),
114
+ );
115
+ </script>
89
116
  </body>
90
117
  </html>
@@ -4,7 +4,7 @@
4
4
 
5
5
  import type { Metadata } from "next";
6
6
  import { isRouteIndexable } from "@domandigital/seo";
7
- import { CookieSettingsButton } from "~site/components/CookieBanner";
7
+ import { CookieSettingsButton, CookieSettingsLink } from "~site/components/CookieBanner";
8
8
  import { JsonLd } from "~site/components/JsonLd";
9
9
  import { facts } from "~site/facts";
10
10
  import { legal, privacyEmail } from "~site/legal";
@@ -40,10 +40,26 @@ export default function CookiesPage() {
40
40
  <strong>Strictly necessary.</strong> Needed for the site to work, including the one that remembers your cookie
41
41
  choice. These do not need your consent.
42
42
  </p>
43
+ <p>
44
+ <strong>Visit statistics.</strong> On by default. We count visits with Cloudflare Web Analytics, which sets no
45
+ cookies and stores nothing on your device. You can switch it off in <CookieSettingsLink />.
46
+ </p>
43
47
  <p>
44
48
  <strong>Measurement.</strong> Off until you choose &quot;Accept measurement&quot;. They count visits and where
45
49
  they come from.
46
50
  </p>
51
+ <dl>
52
+ <dt>Name</dt>
53
+ <dd>Cloudflare Web Analytics</dd>
54
+ <dt>Purpose</dt>
55
+ <dd>Visit statistics</dd>
56
+ <dt>Storage</dt>
57
+ <dd>None (no cookie or local storage)</dd>
58
+ <dt>Default</dt>
59
+ <dd>
60
+ On. Switch off in <CookieSettingsLink />.
61
+ </dd>
62
+ </dl>
47
63
  </section>
48
64
 
49
65
  {thirdParties.length > 0 && (
@@ -7,6 +7,7 @@
7
7
 
8
8
  import type { Metadata } from "next";
9
9
  import { isRouteIndexable } from "@domandigital/seo";
10
+ import { CookieSettingsLink } from "~site/components/CookieBanner";
10
11
  import { JsonLd } from "~site/components/JsonLd";
11
12
  import { facts } from "~site/facts";
12
13
  import { ICO_COMPLAINTS, identity, legal, privacyEmail } from "~site/legal";
@@ -39,8 +40,9 @@ export default function PrivacyPage() {
39
40
  <h2>What we collect</h2>
40
41
  <p>
41
42
  When you contact us we keep what you send: your name, how to reach you and your message. When you use the site,
42
- the server records technical details such as your IP address and browser to keep it running and secure. With
43
- your permission, and only then, we also measure how the site is used.
43
+ the server records technical details such as your IP address and browser to keep it running and secure. We
44
+ count visits without cookies, as set out below. With your permission, and only then, we also use measurement
45
+ cookies to see in more detail how the site is used.
44
46
  </p>
45
47
  </section>
46
48
 
@@ -48,11 +50,26 @@ export default function PrivacyPage() {
48
50
  <h2>Why we are allowed to</h2>
49
51
  <ul>
50
52
  <li>Answering you and doing the work you ask for: taking steps towards a contract, or a contract, Article 6(1)(b).</li>
53
+ <li>Visit statistics: our legitimate interests, Article 6(1)(f). They are on until you switch them off.</li>
51
54
  <li>Measurement cookies: your consent, Article 6(1)(a). They are off until you accept them.</li>
52
55
  <li>Keeping the site running and secure: our legitimate interests, Article 6(1)(f).</li>
53
56
  </ul>
54
57
  </section>
55
58
 
59
+ <section>
60
+ <h2>Analytics</h2>
61
+ <p>
62
+ <strong>Visit statistics (Cloudflare Web Analytics).</strong> We count visits to see which pages people use,
63
+ where they arrive from, and how quickly pages load, so we can improve the site. Cloudflare runs this for us as
64
+ our processor. It sets no cookies and stores nothing on your device. It uses the page address, the referring
65
+ page, your browser and device type, your country, and page timings, and it doesn&apos;t build a profile of you
66
+ or use the data for advertising. Cloudflare keeps these statistics for up to six months, and we keep daily
67
+ totals. The law allows this without asking first, as long as you can say no: switch off{" "}
68
+ <strong>Visit statistics</strong> in <CookieSettingsLink /> and we&apos;ll stop. Our lawful basis is our
69
+ legitimate interest in understanding and improving the site.
70
+ </p>
71
+ </section>
72
+
56
73
  {legal.processors.length > 0 && (
57
74
  <section>
58
75
  <h2>Who we share it with</h2>
@@ -1,51 +1,125 @@
1
1
  "use client";
2
2
 
3
- // The cookie banner, and the button that brings it back. Written by
3
+ // The cookie banner, its settings, and the links that open them. Written by
4
4
  // @domandigital/create-site, from the dd-base banner (Doman-Digital/dd-library).
5
5
  // Unstyled: style it with the site's own classes. Put <CookieBanner /> once
6
6
  // in the root layout; launch:check fails until it is placed.
7
7
  //
8
8
  // It renders nothing on the server and nothing once a choice is stored, so a
9
- // returning visitor never sees it flash. The two buttons carry equal weight:
10
- // refusing must be as easy as accepting.
9
+ // returning visitor never sees it flash. Necessary only and Accept
10
+ // measurement carry equal weight: refusing must be as easy as accepting. They
11
+ // answer the consent-based tools only. Visit statistics (Cloudflare Web
12
+ // Analytics) is a separate switch in Settings, on until the visitor switches
13
+ // it off, and neither button changes it. The settings open from the banner,
14
+ // from <CookieSettingsLink /> and <CookieSettingsButton />, and from the
15
+ // #cookie-settings address. Rule: docs/web-analytics.md in claude-kit.
11
16
 
12
17
  import { useEffect, useState } from "react";
13
- import { SETTINGS_EVENT, getConsent, openCookieSettings, setConsent } from "~site/consent";
18
+ import { SETTINGS_EVENT, getConsent, getStatistics, openCookieSettings, setConsent } from "~site/consent";
19
+
20
+ const SETTINGS_HASH = "#cookie-settings";
21
+
22
+ type View = "closed" | "banner" | "settings";
14
23
 
15
24
  export function CookieBanner({ className }: { className?: string }) {
16
- const [open, setOpen] = useState(false);
25
+ const [view, setView] = useState<View>("closed");
26
+ const [measurement, setMeasurement] = useState(false);
27
+ const [statistics, setStatistics] = useState(true);
28
+
29
+ const openSettings = () => {
30
+ setMeasurement(getConsent()?.measurement ?? false);
31
+ setStatistics(getStatistics());
32
+ setView("settings");
33
+ };
17
34
 
18
35
  useEffect(() => {
19
- setOpen(getConsent() === null);
20
- const reopen = () => setOpen(true);
21
- window.addEventListener(SETTINGS_EVENT, reopen);
22
- return () => window.removeEventListener(SETTINGS_EVENT, reopen);
36
+ const fromAddress = () => {
37
+ if (window.location.hash === SETTINGS_HASH) openSettings();
38
+ };
39
+ if (window.location.hash === SETTINGS_HASH) openSettings();
40
+ else setView(getConsent() === null ? "banner" : "closed");
41
+ window.addEventListener(SETTINGS_EVENT, openSettings);
42
+ window.addEventListener("hashchange", fromAddress);
43
+ return () => {
44
+ window.removeEventListener(SETTINGS_EVENT, openSettings);
45
+ window.removeEventListener("hashchange", fromAddress);
46
+ };
23
47
  }, []);
24
48
 
25
- if (!open) return null;
49
+ if (view === "closed") return null;
26
50
 
27
- const decide = (measurement: boolean) => {
28
- setConsent(measurement);
29
- setOpen(false);
51
+ const decide = (accept: boolean) => {
52
+ setConsent(accept);
53
+ setView("closed");
30
54
  };
31
55
 
56
+ if (view === "banner") {
57
+ return (
58
+ <div className={className} role="region" aria-label="Cookie choices">
59
+ <p>
60
+ We use cookies the site needs to work. With your permission we also use measurement cookies to see how the site is
61
+ used. Visit statistics run without cookies and you can switch them off in settings. <a href="/cookies">Cookie policy</a>
62
+ </p>
63
+ <button type="button" onClick={openSettings}>
64
+ Settings
65
+ </button>
66
+ <button type="button" onClick={() => decide(false)}>
67
+ Necessary only
68
+ </button>
69
+ <button type="button" onClick={() => decide(true)}>
70
+ Accept measurement
71
+ </button>
72
+ </div>
73
+ );
74
+ }
75
+
32
76
  return (
33
- <div className={className} role="region" aria-label="Cookie choices">
34
- <p>
35
- We use cookies the site needs to work. With your permission we also use measurement cookies to see how the site is
36
- used. <a href="/cookies">Cookie policy</a>
37
- </p>
38
- <button type="button" onClick={() => decide(false)}>
39
- Necessary only
77
+ <div className={className} role="region" aria-label="Cookie settings">
78
+ <h2>Cookie settings</h2>
79
+ <p>Strictly necessary cookies are always on. They keep the site working and remember these choices.</p>
80
+ <label>
81
+ <input type="checkbox" role="switch" checked={statistics} onChange={(e) => setStatistics(e.target.checked)} />
82
+ Visit statistics
83
+ </label>
84
+ <p>Counts visits without cookies, to show which pages people use and how fast they load. Used only to improve the site. On unless you switch it off.</p>
85
+ <label>
86
+ <input type="checkbox" role="switch" checked={measurement} onChange={(e) => setMeasurement(e.target.checked)} />
87
+ Measurement cookies
88
+ </label>
89
+ <p>Optional cookies that show us in more detail how the site is used. Off unless you switch them on.</p>
90
+ <button type="button" onClick={() => setView(getConsent() === null ? "banner" : "closed")}>
91
+ Cancel
40
92
  </button>
41
- <button type="button" onClick={() => decide(true)}>
42
- Accept measurement
93
+ <button
94
+ type="button"
95
+ onClick={() => {
96
+ setConsent(measurement, statistics);
97
+ setView("closed");
98
+ }}
99
+ >
100
+ Save choices
43
101
  </button>
44
102
  </div>
45
103
  );
46
104
  }
47
105
 
48
- /** Shows the banner again, so a visitor can change their choice. */
106
+ /** A link to the cookie settings, for the privacy notice and the footer. */
107
+ export function CookieSettingsLink({ className, children = "cookie settings" }: { className?: string; children?: React.ReactNode }) {
108
+ return (
109
+ <a
110
+ href={SETTINGS_HASH}
111
+ className={className}
112
+ onClick={(event) => {
113
+ event.preventDefault();
114
+ openCookieSettings();
115
+ }}
116
+ >
117
+ {children}
118
+ </a>
119
+ );
120
+ }
121
+
122
+ /** Opens the settings, so a visitor can change their choice. */
49
123
  export function CookieSettingsButton({ className }: { className?: string }) {
50
124
  return (
51
125
  <button type="button" className={className} onClick={openCookieSettings}>
@@ -0,0 +1,16 @@
1
+ "use client";
2
+
3
+ // Cloudflare Web Analytics for every visitor, from the first page, unless they
4
+ // have switched Visit statistics off in the cookie settings. Not behind the
5
+ // banner's buttons. Put <WebAnalytics /> once in the root layout; launch:check
6
+ // fails until it is placed and the site's token is in site.facts.ts. Written by
7
+ // @domandigital/create-site. Rule: docs/web-analytics.md in claude-kit.
8
+
9
+ import { useEffect } from "react";
10
+ import { facts } from "~site/facts";
11
+ import { startWebAnalytics } from "~site/web-analytics";
12
+
13
+ export function WebAnalytics() {
14
+ useEffect(() => startWebAnalytics(facts.webAnalytics?.token, { spa: true }), []);
15
+ return null;
16
+ }
@@ -1,36 +1,68 @@
1
- // The visitor's cookie choice, shared by the banner and anything that sets a
2
- // non-essential cookie. Written by @domandigital/create-site, from the
3
- // dd-base banner (Doman-Digital/dd-library).
1
+ // The visitor's cookie choice, shared by the banner and anything that loads a
2
+ // tracker. Written by @domandigital/create-site, from the dd-base banner
3
+ // (Doman-Digital/dd-library).
4
4
  //
5
- // Two states: strictly necessary only (the default, and what no answer
6
- // means), or measurement as well. An analytics loader calls getConsent() and
7
- // loads nothing unless measurement is true, then listens for CONSENT_EVENT so
8
- // a choice made on this page takes effect without a reload. Refusing is as
9
- // easy as accepting, and openCookieSettings() brings the banner back so a
10
- // choice can be changed as easily as it was made (ICO guidance on PECR).
5
+ // Two separate choices in one record:
6
+ // measurement the consent-based tools (GA4, PostHog, pixels). Off until the
7
+ // visitor accepts; no record means off. A tool that sets or
8
+ // reads identifiers calls getConsent() and loads nothing unless
9
+ // measurement is true, then listens for CONSENT_EVENT so a
10
+ // choice made on this page takes effect without a reload.
11
+ // statistics Visit statistics: Cloudflare Web Analytics, loaded by
12
+ // lib/web-analytics.ts. On until the visitor objects; no record
13
+ // means on. Accept and Reject never change it.
14
+ //
15
+ // Refusing is as easy as accepting, and openCookieSettings() brings the
16
+ // settings back so a choice can be changed as easily as it was made (ICO
17
+ // guidance on PECR). The rule is docs/web-analytics.md in claude-kit.
18
+ //
19
+ // A v1 record ({ measurement, decidedAt }) is read as v2 with statistics on,
20
+ // and is rewritten as v2 the next time the visitor saves a choice.
11
21
 
12
22
  export const CONSENT_KEY = "dd-cookie-consent";
13
23
  /** Fired on window with the new ConsentRecord as detail. */
14
24
  export const CONSENT_EVENT = "dd-cookie-consent";
15
- /** Fired on window to show the banner again. */
25
+ /** Fired on window to open the cookie settings. */
16
26
  export const SETTINGS_EVENT = "dd-cookie-settings";
17
27
 
18
- export type ConsentRecord = { measurement: boolean; decidedAt: string; version: "v1" };
28
+ export type ConsentRecord = { measurement: boolean; statistics: boolean; decidedAt: string; version: "v2" };
29
+
30
+ /** Reads a stored value as a v2 record, migrating v1. Anything else is no record. */
31
+ export function parseConsent(raw: string | null): ConsentRecord | null {
32
+ if (!raw) return null;
33
+ try {
34
+ const parsed = JSON.parse(raw) as Record<string, unknown> | null;
35
+ if (!parsed || typeof parsed !== "object") return null;
36
+ if (parsed.version !== "v1" && parsed.version !== "v2") return null;
37
+ if (typeof parsed.measurement !== "boolean") return null;
38
+ return {
39
+ measurement: parsed.measurement,
40
+ statistics: parsed.version === "v2" && typeof parsed.statistics === "boolean" ? parsed.statistics : true,
41
+ decidedAt: typeof parsed.decidedAt === "string" ? parsed.decidedAt : "",
42
+ version: "v2",
43
+ };
44
+ } catch {
45
+ return null;
46
+ }
47
+ }
19
48
 
20
49
  export function getConsent(): ConsentRecord | null {
21
50
  if (typeof window === "undefined") return null;
22
51
  try {
23
- const raw = window.localStorage.getItem(CONSENT_KEY);
24
- if (!raw) return null;
25
- const parsed = JSON.parse(raw) as ConsentRecord;
26
- return parsed.version === "v1" && typeof parsed.measurement === "boolean" ? parsed : null;
52
+ return parseConsent(window.localStorage.getItem(CONSENT_KEY));
27
53
  } catch {
28
54
  return null;
29
55
  }
30
56
  }
31
57
 
32
- export function setConsent(measurement: boolean): ConsentRecord {
33
- const record: ConsentRecord = { measurement, decidedAt: new Date().toISOString(), version: "v1" };
58
+ /** Visit statistics are on unless the visitor has switched them off. */
59
+ export function getStatistics(): boolean {
60
+ return getConsent()?.statistics ?? true;
61
+ }
62
+
63
+ /** Saves a choice. Leaving `statistics` out keeps whatever it is now. */
64
+ export function setConsent(measurement: boolean, statistics: boolean = getStatistics()): ConsentRecord {
65
+ const record: ConsentRecord = { measurement, statistics, decidedAt: new Date().toISOString(), version: "v2" };
34
66
  try {
35
67
  window.localStorage.setItem(CONSENT_KEY, JSON.stringify(record));
36
68
  } catch {
@@ -104,6 +104,12 @@ export type SiteFacts = {
104
104
  previousHosts: string[];
105
105
  /** Optional so a facts file written before the legal pages still compiles. */
106
106
  legal?: LegalFacts;
107
+ /**
108
+ * Cloudflare Web Analytics. The token is the site's public id from Cloudflare's
109
+ * Web Analytics (manual setup, never automatic setup); null loads nothing and
110
+ * launch:check fails until it is set. Optional so older facts files compile.
111
+ */
112
+ webAnalytics?: { token: string | null };
107
113
  };
108
114
 
109
115
  const DAY_NAMES: Record<Day, string> = {
@@ -0,0 +1,47 @@
1
+ // Cloudflare Web Analytics, loaded for every visitor from the first page
2
+ // unless they have switched Visit statistics off in the cookie settings. Not
3
+ // behind the banner's Accept and Reject. Written by @domandigital/create-site,
4
+ // from the dd-base loader (Doman-Digital/dd-library).
5
+ //
6
+ // Manual beacon only: never turn on Cloudflare's automatic setup, which a
7
+ // visitor's objection cannot stop. The rule is docs/web-analytics.md in
8
+ // claude-kit. If the site sets a CSP it allows
9
+ // script-src https://static.cloudflareinsights.com/beacon.min.js
10
+ // connect-src https://cloudflareinsights.com
11
+
12
+ import { CONSENT_EVENT, getStatistics } from "~site/consent";
13
+ import type { ConsentRecord } from "~site/consent";
14
+
15
+ export const BEACON_SRC = "https://static.cloudflareinsights.com/beacon.min.js";
16
+
17
+ export type BeaconOptions = {
18
+ /** True for a client-routed site: the beacon then counts route changes. */
19
+ spa?: boolean;
20
+ };
21
+
22
+ /** Adds the beacon once. Returns true if it added it. A null token loads nothing. */
23
+ export function loadBeacon(token: string | null | undefined, options: BeaconOptions = {}): boolean {
24
+ if (!token) return false;
25
+ if (document.querySelector("script[data-cf-beacon]")) return false;
26
+ const script = document.createElement("script");
27
+ script.defer = true;
28
+ script.src = BEACON_SRC;
29
+ script.setAttribute("data-cf-beacon", JSON.stringify(options.spa ? { token, spa: true } : { token }));
30
+ document.head.append(script);
31
+ return true;
32
+ }
33
+
34
+ /**
35
+ * Loads the beacon now unless the visitor has objected, and again if they
36
+ * switch Visit statistics back on. Switching it off stops the beacon from the
37
+ * next page, because a script already running cannot be recalled. Returns the
38
+ * clean-up for the listener.
39
+ */
40
+ export function startWebAnalytics(token: string | null | undefined, options: BeaconOptions = {}): () => void {
41
+ if (getStatistics()) loadBeacon(token, options);
42
+ const onChoice = (event: Event) => {
43
+ if ((event as CustomEvent<ConsentRecord>).detail?.statistics) loadBeacon(token, options);
44
+ };
45
+ window.addEventListener(CONSENT_EVENT, onChoice);
46
+ return () => window.removeEventListener(CONSENT_EVENT, onChoice);
47
+ }
@@ -59,6 +59,12 @@ describe.runIf(mode === "launch")("ready to launch", () => {
59
59
  expect(placed).toBe(true);
60
60
  });
61
61
 
62
+ test("Cloudflare Web Analytics is placed on the site and has its token", () => {
63
+ const placed = sourceFiles().some((file) => !/WebAnalytics\.(tsx|astro)$/.test(file) && readFileSync(file, "utf8").includes("<WebAnalytics"));
64
+ expect(placed).toBe(true);
65
+ expect(facts.webAnalytics?.token ?? null).not.toBeNull();
66
+ });
67
+
62
68
  test("the legal pages have what every site needs: retention, the processors, the governing law, a review date", () => {
63
69
  const missing = [
64
70
  legal.retention ? null : "legal.retention",