Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
feat(website): measure audience and download clicks with cookieless PostHog
EtienneLescotcda5493c71f8
diff --git a/website/docusaurus.config.ts b/website/docusaurus.config.tsindex ee792e6d8..c21c52351 100644--- a/website/docusaurus.config.ts+++ b/website/docusaurus.config.ts@@ -407,6 +407,9 @@ export default async function createConfig(): Promise<Config> {},},+ // Audience and download measurement (PostHog, cookieless).+ clientModules: ["./src/analytics.ts"],+headTags: [{tagName: "link",diff --git a/website/package-lock.json b/website/package-lock.jsonindex 99e29127c..4cf26245a 100644--- a/website/package-lock.json+++ b/website/package-lock.json@@ -16,6 +16,7 @@"@mdx-js/react": "^3.1.0","clsx": "^2.1.1","lucide-react": "^1.23.0",+ "posthog-js": "~1.435.1","prism-react-renderer": "^2.4.1","react": "^18.3.1","react-dom": "^18.3.1"@@ -5579,6 +5580,31 @@"integrity": "sha512-wwQAWhWSuHaag8c4q/KN/vCoeOJYshAIvMQwD4GpSb3OiZklFfvAgmj0VCBBImRpuF/aFgIRzllXlVX93Jevww==","license": "MIT"},+ "node_modules/@posthog/browser-common": {+ "version": "0.9.4",+ "resolved": "https://registry.npmjs.org/@posthog/browser-common/-/browser-common-0.9.4.tgz",+ "integrity": "sha512-QlG0WZFG9iTp9cmXTypB4cgnxBAD3GImrj9AwmA84uh8uy5vIVgVLjoTTdOAW29XL+kh/eLn/5ZtBQt2JQfR+w==",+ "license": "MIT",+ "dependencies": {+ "@posthog/core": "^1.57.4",+ "@posthog/types": "^1.415.2"+ }+ },+ "node_modules/@posthog/core": {+ "version": "1.59.0",+ "resolved": "https://registry.npmjs.org/@posthog/core/-/core-1.59.0.tgz",+ "integrity": "sha512-KRq26v5fXYnwV5wqTAXzPyQLCrBzzhK78QRl7UyEaPFZ4RPmVo1pBObRDbK350ah+8hTfQPanu5mM8c4CaSn5g==",+ "license": "MIT",+ "dependencies": {+ "@posthog/types": "^1.416.0"+ }+ },+ "node_modules/@posthog/types": {+ "version": "1.416.0",+ "resolved": "https://registry.npmjs.org/@posthog/types/-/types-1.416.0.tgz",+ "integrity": "sha512-0/9+02s/0uDyrH4G/qUg1yyl6gXUg8Uuxw/PlDad3KLzo9FFS9zS/kAQaEshx/saVGupj1aAy/4EUBxWisBogw==",+ "license": "MIT"+ },"node_modules/@rspack/binding": {"version": "1.7.12","resolved": "https://registry.npmjs.org/@rspack/binding/-/binding-1.7.12.tgz",@@ -6871,6 +6897,13 @@"@types/node": "*"}},+ "node_modules/@types/trusted-types": {+ "version": "2.0.7",+ "resolved": "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.7.tgz",+ "integrity": "sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw==",+ "license": "MIT",+ "optional": true+ },"node_modules/@types/unist": {"version": "3.0.3","resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.3.tgz",@@ -9274,6 +9307,15 @@"url": "https://github.com/fb55/domhandler?sponsor=1"}},+ "node_modules/dompurify": {+ "version": "3.4.17",+ "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-3.4.17.tgz",+ "integrity": "sha512-B/pSlYVHQ58kqISD/yDjuJ1yfzI34m1gF4lAod2bwSRhiN4K5Cl3H8Af7hqB2PmTL911tdEudnnXn5FnhRoz0w==",+ "license": "(MPL-2.0 OR Apache-2.0)",+ "optionalDependencies": {+ "@types/trusted-types": "^2.0.7"+ }+ },"node_modules/domutils": {"version": "3.2.2","resolved": "https://registry.npmjs.org/domutils/-/domutils-3.2.2.tgz",@@ -9976,6 +10018,12 @@"node": ">=0.4.0"}},+ "node_modules/fflate": {+ "version": "0.4.9",+ "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.4.9.tgz",+ "integrity": "sha512-zdxgIEddhfsyCaWpJ2SdXEP8ZMrKJ6+5jl4OupODcywU0IhRk6gdXuVGcPICyfx2H97hVK7xmJtRLPjkxAX8Vw==",+ "license": "MIT"+ },"node_modules/file-loader": {"version": "6.2.0","resolved": "https://registry.npmjs.org/file-loader/-/file-loader-6.2.0.tgz",@@ -16678,6 +16726,54 @@"postcss": "^8.4.31"}},+ "node_modules/posthog-js": {+ "version": "1.435.9",+ "resolved": "https://registry.npmjs.org/posthog-js/-/posthog-js-1.435.9.tgz",+ "integrity": "sha512-Ic0zS5eGWlo/0oEnWc46iL0DD/zlkPPjM5HkrTWCGHis8wqioU1nwBAwfFnqz+u5WMNeRlVX+4IbPEtOmT5NEw==",+ "license": "(Apache-2.0 AND MIT)",+ "dependencies": {+ "@posthog/browser-common": "^0.9.1",+ "@posthog/core": "^1.55.3",+ "@posthog/types": "^1.413.0",+ "core-js": "^3.49.0",+ "dompurify": "^3.4.13",+ "fflate": "^0.4.8",+ "preact": "^10.29.3",+ "query-selector-shadow-dom": "^1.0.1",+ "web-vitals": "^6.2.1",+ "web-vitals-soft-navs": "npm:[email protected]"+ },+ "peerDependencies": {+ "@types/react": ">=16.8.0",+ "react": ">=16.8.0"+ },+ "peerDependenciesMeta": {+ "@types/react": {+ "optional": true+ },+ "react": {+ "optional": true+ }+ }+ },+ "node_modules/preact": {+ "version": "10.29.8",+ "resolved": "https://registry.npmjs.org/preact/-/preact-10.29.8.tgz",+ "integrity": "sha512-ej2aVZ+vZ8WO7tvlQWRM9N63A0KzF9q4mWJfDUHgYaIofWY9hu74QdnQrjoPMmZi2/nZ5gN0bJCQF49xQqx09Q==",+ "license": "MIT",+ "funding": {+ "type": "opencollective",+ "url": "https://opencollective.com/preact"+ },+ "peerDependencies": {+ "preact-render-to-string": ">=5"+ },+ "peerDependenciesMeta": {+ "preact-render-to-string": {+ "optional": true+ }+ }+ },"node_modules/pretty-error": {"version": "4.0.0","resolved": "https://registry.npmjs.org/pretty-error/-/pretty-error-4.0.0.tgz",@@ -16845,6 +16941,12 @@"url": "https://github.com/sponsors/ljharb"}},+ "node_modules/query-selector-shadow-dom": {+ "version": "1.0.1",+ "resolved": "https://registry.npmjs.org/query-selector-shadow-dom/-/query-selector-shadow-dom-1.0.1.tgz",+ "integrity": "sha512-lT5yCqEBgfoMYpf3F2xQRK7zEr1rhIIZuceDK6+xRkJQ4NMbHTwXqk4NkwDwQMNqXgG9r9fyHnzwNVs6zV5KRw==",+ "license": "MIT"+ },"node_modules/queue-microtask": {"version": "1.2.3","resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz",@@ -19510,6 +19612,19 @@"url": "https://github.com/sponsors/wooorm"}},+ "node_modules/web-vitals": {+ "version": "6.2.3",+ "resolved": "https://registry.npmjs.org/web-vitals/-/web-vitals-6.2.3.tgz",+ "integrity": "sha512-Dmy+vdO1UPMqXiAtZSNayhl4f794Bxfd94W4HIj2HlYtczEQfEOon969memlcpcHrTuOKLa5baFjX7WbgmOq+A==",+ "license": "Apache-2.0"+ },+ "node_modules/web-vitals-soft-navs": {+ "name": "web-vitals",+ "version": "6.2.1",+ "resolved": "https://registry.npmjs.org/web-vitals/-/web-vitals-6.2.1.tgz",+ "integrity": "sha512-rLcLXA2sx6+9dE88NHFubwTtGxpK4yYBLj6qHPdFoCaLr0cXGb4efOqtKLlm4loGA4OEKHIQKMKzZkKyOh5ctw==",+ "license": "Apache-2.0"+ },"node_modules/webpack": {"version": "5.107.2","resolved": "https://registry.npmjs.org/webpack/-/webpack-5.107.2.tgz",diff --git a/website/package.json b/website/package.jsonindex 01d46f3a4..5018a1e35 100644--- a/website/package.json+++ b/website/package.json@@ -26,6 +26,7 @@"@mdx-js/react": "^3.1.0","clsx": "^2.1.1","lucide-react": "^1.23.0",+ "posthog-js": "~1.435.1","prism-react-renderer": "^2.4.1","react": "^18.3.1","react-dom": "^18.3.1"diff --git a/website/src/analytics.ts b/website/src/analytics.tsnew file mode 100644index 000000000..61b8df7a3--- /dev/null+++ b/website/src/analytics.ts@@ -0,0 +1,29 @@+import { downloadClick } from "./lib/download-target";++// A project token is public by design: it can only send events, not read them.+const POSTHOG_TOKEN = "phc_TODO";++// The live domain only, so neither `npm run dev`, a local `serve` nor a preview+// deployment counts. posthog-js is fetched as its own chunk, after hydration has+// started, so it never holds up the first paint.+if (typeof window !== "undefined" && window.location.hostname === "getopenscreen.com") {+ void import("posthog-js").then(({ default: posthog }) => {+ posthog.init(POSTHOG_TOKEN, {+ api_host: "https://eu.i.posthog.com",+ defaults: "2026-08-30",+ // Nothing stored in the browser, so no consent banner. PostHog counts+ // visitors with a daily hash it computes server-side, which needs+ // "Cookieless server hash mode" on in the project settings.+ cookieless_mode: "always",+ person_profiles: "never",+ });+ // One listener for every download link on the site: the landing page's+ // button, /download/'s cards and any page that links a release asset.+ document.addEventListener("click", (event) => {+ const link = event.target instanceof Element ? event.target.closest("a") : null;+ const download = link ? downloadClick(link.href) : null;+ // sendBeacon survives the navigation a Store or fallback link starts.+ if (download) posthog.capture("download_clicked", download, { transport: "sendBeacon" });+ });+ });+}diff --git a/website/src/lib/download-target.test.ts b/website/src/lib/download-target.test.tsindex 2a5c2076c..f4c9cb089 100644--- a/website/src/lib/download-target.test.ts+++ b/website/src/lib/download-target.test.ts@@ -4,6 +4,7 @@ import { test } from "node:test";import {browserDownloadTarget,directDownloadUrl,+ downloadClick,downloadTarget,STORE_INSTALLER_URL,} from "./download-target.ts";@@ -149,3 +150,16 @@ test("architecture detection asks for one hint and tolerates refusal and hidden);assert.deepEqual(refused, { os: "macos", kind: null });});++test("a download click names the asset kind and the release, and other links are not downloads", () => {+ const base = "https://github.com/getopenscreen/openscreen/releases/download/v2.0.0";+ assert.deepEqual(downloadClick(`${base}/Openscreen-mac-arm64.dmg`), {+ kind: "macArm",+ version: "v2.0.0",+ file: "Openscreen-mac-arm64.dmg",+ });+ assert.equal(downloadClick(`${base}/Openscreen-Setup-arm64.exe`)?.kind, "other");+ assert.equal(downloadClick(STORE_INSTALLER_URL)?.kind, "store");+ assert.equal(downloadClick("https://github.com/getopenscreen/openscreen/releases/latest"), null);+ assert.equal(downloadClick("https://apps.microsoft.com/detail/9MXQ1HQJL5G5"), null);+});diff --git a/website/src/lib/download-target.ts b/website/src/lib/download-target.tsindex 8cbfec07d..a5de68d45 100644--- a/website/src/lib/download-target.ts+++ b/website/src/lib/download-target.ts@@ -1,4 +1,4 @@-import { type AssetKind, findAsset, type LatestRelease } from "./release.ts";+import { ASSET_PATTERNS, type AssetKind, findAsset, type LatestRelease } from "./release.ts";export const STORE_URL = "https://apps.microsoft.com/detail/9MXQ1HQJL5G5";// The endpoint used by Microsoft's own Store badge in direct-install mode.@@ -108,3 +108,21 @@ export function directDownloadUrl(target: DownloadTarget, release: LatestReleaseif (target.os === "windows") return STORE_INSTALLER_URL;return target.kind ? (findAsset(release, target.kind)?.url ?? null) : null;}++export type DownloadClick = {+ kind: AssetKind | "store" | "other";+ version: string | null;+ file: string | null;+};++/** What a link downloads, for the analytics event, or null when it downloads nothing. */+export function downloadClick(href: string): DownloadClick | null {+ if (href.startsWith(STORE_INSTALLER_URL)) return { kind: "store", version: null, file: null };+ const match = /\/releases\/download\/([^/]+)\/([^/?#]+)/.exec(href);+ if (!match) return null;+ const file = decodeURIComponent(match[2]);+ const kind = (Object.keys(ASSET_PATTERNS) as AssetKind[]).find((k) =>+ ASSET_PATTERNS[k].test(file),+ );+ return { kind: kind ?? "other", version: match[1], file };+}