Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: add server-side posthog client
Marc Seitz7d957155de3a
diff --git a/lib/posthog.ts b/lib/posthog.tsindex abc69aad..dbdc742c 100644--- a/lib/posthog.ts+++ b/lib/posthog.ts@@ -1,3 +1,5 @@+import { PostHog } from "posthog-node";+export function getPostHogConfig(): { key: string; host: string } | null {const postHogKey = process.env.NEXT_PUBLIC_POSTHOG_KEY;const postHogHost = `${process.env.NEXT_PUBLIC_BASE_URL}/ingest`;@@ -11,3 +13,18 @@ export function getPostHogConfig(): { key: string; host: string } | null {host: postHogHost,};}++export function getPostHogServerClient() {+ const posthogConfig = getPostHogConfig();+ const isPostHogEnabled = !!posthogConfig;++ if (!isPostHogEnabled) {+ return null;+ }++ const client = new PostHog(posthogConfig.key, {+ host: posthogConfig.host,+ });++ return client;+}diff --git a/package-lock.json b/package-lock.jsonindex 857db094..94ce752d 100644--- a/package-lock.json+++ b/package-lock.json@@ -84,6 +84,7 @@"openai": "^4.20.0","postcss": "^8.4.35","posthog-js": "^1.110.0",+ "posthog-node": "^3.6.3","react": "^18.2.0","react-colorful": "^5.6.1","react-dom": "^18.2.0",@@ -6193,6 +6194,16 @@"node": ">=4"}},+ "node_modules/axios": {+ "version": "1.6.7",+ "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.7.tgz",+ "integrity": "sha512-/hDJGff6/c7u0hDkvkGxR/oy6CbCs8ziCsC7SqmhjfozqiJGc8Z11wrv9z9lYfY4K8l+H9TpjcMDX0xOZmx+RA==",+ "dependencies": {+ "follow-redirects": "^1.15.4",+ "form-data": "^4.0.0",+ "proxy-from-env": "^1.1.0"+ }+ },"node_modules/axobject-query": {"version": "3.2.1","resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-3.2.1.tgz",@@ -8635,6 +8646,25 @@"resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.7.tgz","integrity": "sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ=="},+ "node_modules/follow-redirects": {+ "version": "1.15.5",+ "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.5.tgz",+ "integrity": "sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==",+ "funding": [+ {+ "type": "individual",+ "url": "https://github.com/sponsors/RubenVerborgh"+ }+ ],+ "engines": {+ "node": ">=4.0"+ },+ "peerDependenciesMeta": {+ "debug": {+ "optional": true+ }+ }+ },"node_modules/for-each": {"version": "0.3.3","resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz",@@ -14085,6 +14115,18 @@"preact": "^10.19.3"}},+ "node_modules/posthog-node": {+ "version": "3.6.3",+ "resolved": "https://registry.npmjs.org/posthog-node/-/posthog-node-3.6.3.tgz",+ "integrity": "sha512-JB+ei0LkwE+rKHyW5z79Nd1jUaGxU6TvkfjFqY9vQaHxU5aU8dRl0UUaEmZdZbHwjp3WmXCBQQRNyimwbNQfCw==",+ "dependencies": {+ "axios": "^1.6.2",+ "rusha": "^0.8.14"+ },+ "engines": {+ "node": ">=15.0.0"+ }+ },"node_modules/preact": {"version": "10.19.6","resolved": "https://registry.npmjs.org/preact/-/preact-10.19.6.tgz",@@ -14201,6 +14243,11 @@"resolved": "https://registry.npmjs.org/proto-list/-/proto-list-1.2.4.tgz","integrity": "sha512-vtK/94akxsTMhe0/cbfpR+syPuszcuwhqVjJq26CuNDgFGj682oRBXOP5MJpv2r7JtE8MsiepGIqvvOTBwn2vA=="},+ "node_modules/proxy-from-env": {+ "version": "1.1.0",+ "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",+ "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="+ },"node_modules/pump": {"version": "3.0.0","resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz",@@ -15777,6 +15824,11 @@"queue-microtask": "^1.2.2"}},+ "node_modules/rusha": {+ "version": "0.8.14",+ "resolved": "https://registry.npmjs.org/rusha/-/rusha-0.8.14.tgz",+ "integrity": "sha512-cLgakCUf6PedEu15t8kbsjnwIFFR2D4RfL+W3iWFJ4iac7z4B0ZI8fxy4R3J956kAI68HclCFGL8MPoUVC3qVA=="+ },"node_modules/sade": {"version": "1.8.1","resolved": "https://registry.npmjs.org/sade/-/sade-1.8.1.tgz",diff --git a/package.json b/package.jsonindex 7fb21fbf..f47545e4 100644--- a/package.json+++ b/package.json@@ -92,6 +92,7 @@"openai": "^4.20.0","postcss": "^8.4.35","posthog-js": "^1.110.0",+ "posthog-node": "^3.6.3","react": "^18.2.0","react-colorful": "^5.6.1","react-dom": "^18.2.0",