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
4 changes: 4 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ jobs:
# Empty with the custom domain; set to /website to serve from
# https://napi-bindings.github.io/website instead.
NEXT_PUBLIC_BASE_PATH: ""
# Google Analytics 4 measurement ID, from the repository variable
# GA_MEASUREMENT_ID. Left empty for pull requests, so their builds
# contain neither the consent banner nor the Google tag.
NEXT_PUBLIC_GA_ID: ${{ github.event_name != 'pull_request' && vars.GA_MEASUREMENT_ID || '' }}

- uses: actions/upload-artifact@v4
with:
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,25 @@ and a `.nojekyll` file so that `_next/` is served.
To serve the site from `https://napi-bindings.github.io/website` instead of the custom domain,
set `NEXT_PUBLIC_BASE_PATH: /website` in the workflow and remove the `cname` input.

## Analytics

The site counts page views with Google Analytics 4, through `GoogleAnalytics` from
[`@next/third-parties`](https://nextjs.org/docs/app/guides/third-party-libraries#google-analytics).
No custom events are sent.

- The Google tag is loaded **only after the visitor accepts** the banner (`src/components/cookie-banner.tsx`):
before that, no request reaches Google. The choice is kept in `localStorage` for six months
(`src/lib/analytics-consent.ts`); "Cookie preferences" in the footer withdraws it, deletes the `_ga*`
cookies and shows the banner again. `/privacy/` describes all of this to visitors.
- Navigations between pages are measured by GA4 itself: in the web data stream, Enhanced measurement must
have Page views on, with "Page changes based on browser history events" checked.
- The measurement ID comes from the repository variable `GA_MEASUREMENT_ID`
(Settings → Secrets and variables → Actions → Variables) and is inlined at build time as
`NEXT_PUBLIC_GA_ID`. Pull request builds and local builds leave it empty: no banner, no tag.

To try it locally, create `.env.local` (ignored by git) with the line `NEXT_PUBLIC_GA_ID=G-XXXXXXXXXX`
and run `npm run dev`; in development the tag runs in debug mode, so the events show up in GA4 DebugView.

## License

Code: [Apache-2.0](LICENSE). Node-API documentation content: © Node.js contributors, MIT license.
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"dependencies": {
"@base-ui/react": "^1.9.0",
"@next/third-parties": "16.4.6",
"@shikijs/rehype": "^4.6.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
Expand Down
2 changes: 2 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Metadata, Viewport } from "next"
import { GeistMono } from "geist/font/mono"
import { GeistSans } from "geist/font/sans"

import { Analytics } from "@/components/analytics"
import { SiteFooter } from "@/components/site-footer"
import { SiteHeader } from "@/components/site-header"
import { ThemeProvider } from "@/components/theme-provider"
Expand Down Expand Up @@ -52,6 +53,7 @@ export default function RootLayout({ children }: LayoutProps<"/">) {
{children}
</main>
<SiteFooter generatedAt={dataGeneratedAt} />
<Analytics />
</TooltipProvider>
</ThemeProvider>
</body>
Expand Down
131 changes: 131 additions & 0 deletions src/app/privacy/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import type { Metadata } from "next"
import type { ReactNode } from "react"

import { CookiePreferences } from "@/components/cookie-preferences"
import { Container, PageHeader } from "@/components/page-header"
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
import { siteConfig } from "@/lib/site"

export const metadata: Metadata = {
title: "Privacy",
description: "What napi-bindings.dev measures, which cookies it sets and how to change your choice.",
alternates: { canonical: "/privacy/" },
}

const LAST_UPDATED = "November 21, 2026"

const COOKIES = [
{ name: "_ga", purpose: "Tells visitors apart, so that visits can be counted.", duration: "2 years" },
{ name: "_ga_<id>", purpose: "Keeps the state of the current visit (session).", duration: "2 years" },
]

function Section({ title, children }: { title: string; children: ReactNode }) {
return (
<section className="flex flex-col gap-3">
<h2 className="text-xl font-semibold tracking-tight">{title}</h2>
<div className="text-muted-foreground flex flex-col gap-3 leading-relaxed">{children}</div>
</section>
)
}

export default function PrivacyPage() {
const issues = `${siteConfig.github}/website/issues`

return (
<Container className="flex max-w-3xl flex-col gap-10 py-10">
<PageHeader
eyebrow="Site"
title="Privacy"
description="This site measures page views with Google Analytics, and only if you agree. Nothing else is collected."
className="pb-0"
/>

<Section title="What is measured">
<p>
If you accept, Google Analytics 4 records the pages you open: the page address and title, the page you came
from, the approximate country, the device and browser type, the language and the screen size. The site sends
no other events, uses no advertising features and has Google signals turned off. Google Analytics 4 does not
store IP addresses.
</p>
<p>
If you decline, or make no choice, the Google tag is not loaded and no data is sent to Google. The site works
the same either way.
</p>
</Section>

<Section title="Cookies and local storage">
<p>Google Analytics sets these cookies, only after you accept:</p>
<div className="overflow-hidden rounded-xl border">
<Table>
<TableHeader>
<TableRow>
<TableHead className="w-32">Cookie</TableHead>
<TableHead>Purpose</TableHead>
<TableHead className="w-24">Duration</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{COOKIES.map((cookie) => (
<TableRow key={cookie.name}>
<TableCell className="font-mono text-xs">{cookie.name}</TableCell>
<TableCell className="whitespace-normal">{cookie.purpose}</TableCell>
<TableCell>{cookie.duration}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</div>
<p>
Your choice itself is kept in your browser&apos;s local storage (
<code className="text-foreground font-mono text-xs">napi-bindings:analytics-consent</code>) for six months,
after which the site asks again. It is never sent anywhere. The light or dark theme you pick is kept the same
way.
</p>
</Section>

<Section title="Who receives the data">
<p>
Google Analytics is provided by Google Ireland Limited. Google may process the data in the United States,
under the EU-U.S. Data Privacy Framework. The analytics data is kept for two months and then deleted;
only aggregated reports remain.
</p>
<p>
The site is hosted on GitHub Pages. GitHub may log technical data, such as IP addresses, to deliver and
secure the pages, as described in the{" "}
<a
href="https://docs.github.com/site-policy/privacy-policies/github-general-privacy-statement"
target="_blank"
rel="noreferrer"
className="text-foreground underline underline-offset-4"
>
GitHub privacy statement
</a>
.
</p>
</Section>

<Section title="Change your choice">
<p>
You can withdraw or change your choice at any time: the Google Analytics cookies are deleted and the banner
is shown again. The same link is in the footer of every page.
</p>
<div>
<CookiePreferences
label="Change cookie preferences"
className="text-foreground underline underline-offset-4"
/>
</div>
<p>
For questions about this page, or to exercise your rights under the GDPR, contact the maintainers of the
napi-bindings organization by{" "}
<a href={issues} target="_blank" rel="noreferrer" className="text-foreground underline underline-offset-4">
opening an issue
</a>
. You can also lodge a complaint with your data protection authority.
</p>
</Section>

<p className="text-muted-foreground text-xs">Last updated: {LAST_UPDATED}.</p>
</Container>
)
}
1 change: 1 addition & 0 deletions src/app/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default function sitemap(): MetadataRoute.Sitemap {
"/projects/",
"/ecosystem/",
"/activity/",
"/privacy/",
...guideSections.map((s) => routes.section(s.id)),
...nodeApi.symbols.map((s) => routes.symbol(s.name)),
...projects.flatMap((p) => [
Expand Down
22 changes: 22 additions & 0 deletions src/components/analytics.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"use client"

import { GoogleAnalytics } from "@next/third-parties/google"

import { CookieBanner } from "@/components/cookie-banner"
import { GA_ID, useConsent } from "@/lib/analytics-consent"

/**
* Google Analytics 4, page views only. The Google tag is mounted after the
* visitor accepts; navigations between pages are measured by GA4 itself
* ("Page changes based on browser history events" in Enhanced measurement).
*/
export function Analytics() {
const consent = useConsent()

if (!GA_ID) return null
if (consent === "granted") {
return <GoogleAnalytics gaId={GA_ID} debugMode={process.env.NODE_ENV === "development"} />
}
if (consent === "unset") return <CookieBanner />
return null
}
31 changes: 31 additions & 0 deletions src/components/cookie-banner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"use client"

import Link from "next/link"

import { Button } from "@/components/ui/button"
import { setConsent } from "@/lib/analytics-consent"

/** A small, non-blocking notice: both choices have the same weight. */
export function CookieBanner() {
return (
<section
aria-label="Cookie consent"
className="bg-popover text-popover-foreground animate-in fade-in slide-in-from-bottom-2 fixed inset-x-3 bottom-3 z-50 flex flex-col gap-3 rounded-xl border p-4 text-sm shadow-lg motion-reduce:animate-none sm:inset-x-auto sm:right-4 sm:bottom-4 sm:max-w-sm"
>
<p className="text-muted-foreground text-pretty">
We use Google Analytics cookies to count page views, only if you agree.{" "}
<Link href="/privacy/" className="text-foreground underline underline-offset-4">
Privacy
</Link>
</p>
<div className="flex justify-end gap-2">
<Button variant="outline" size="sm" onClick={() => setConsent(false)}>
Decline
</Button>
<Button variant="outline" size="sm" onClick={() => setConsent(true)}>
Accept
</Button>
</div>
</section>
)
}
14 changes: 14 additions & 0 deletions src/components/cookie-preferences.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use client"

import { GA_ID, revokeConsent } from "@/lib/analytics-consent"
import { cn } from "@/lib/utils"

/** Withdraws the analytics choice and shows the banner again. */
export function CookiePreferences({ className, label = "Cookie preferences" }: { className?: string; label?: string }) {
if (!GA_ID) return null
return (
<button type="button" onClick={revokeConsent} className={cn("hover:text-foreground cursor-pointer", className)}>
{label}
</button>
)
}
13 changes: 10 additions & 3 deletions src/components/site-footer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Link from "next/link"

import { CookiePreferences } from "@/components/cookie-preferences"
import { Logo } from "@/components/logo"
import { PROJECTS } from "@/config/projects"
import { formatDate } from "@/lib/utils"
Expand Down Expand Up @@ -70,9 +71,15 @@ export function SiteFooter({ generatedAt }: { generatedAt: string }) {
© napi-bindings contributors. Code licensed under Apache-2.0. Node-API reference content © Node.js
contributors, MIT license.
</p>
<a href={`${siteConfig.github}/website`} target="_blank" rel="noreferrer" className="hover:text-foreground">
Edit this site on GitHub
</a>
<div className="flex flex-wrap gap-x-4 gap-y-2">
<Link href="/privacy/" className="hover:text-foreground">
Privacy
</Link>
<CookiePreferences />
<a href={`${siteConfig.github}/website`} target="_blank" rel="noreferrer" className="hover:text-foreground">
Edit this site on GitHub
</a>
</div>
</div>
</div>
</footer>
Expand Down
Loading
Loading