Skip to content

Commit 1fa3ff6

Browse files
thegdsksglinr
andcommitted
feat(docs): switch to SSR with PostHog reverse proxy and GA
- Remove static export, enable Next.js SSR for Netlify - Add /ingest/* rewrites to proxy PostHog (bypasses ad blockers) - Add Google Analytics support via NEXT_PUBLIC_GA_ID - Remove hardcoded keys, all analytics config via env vars Co-Authored-By: Glinr <bot@glincker.com>
1 parent 78b8ace commit 1fa3ff6

3 files changed

Lines changed: 20 additions & 8 deletions

File tree

apps/docs/next.config.mjs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,8 @@ const basePath = process.env.NEXT_PUBLIC_BASE_PATH || ''
1414

1515
export default withNextra({
1616
reactStrictMode: true,
17-
output: 'export',
1817
trailingSlash: true,
1918
basePath,
20-
env: {
21-
NEXT_PUBLIC_POSTHOG_KEY: process.env.NEXT_PUBLIC_POSTHOG_KEY,
22-
NEXT_PUBLIC_POSTHOG_HOST: process.env.NEXT_PUBLIC_POSTHOG_HOST,
23-
},
2419
assetPrefix: basePath ? `${basePath}/` : undefined,
2520
webpack: (config) => {
2621
// Force a single React instance for linked local packages (featuredrop -> root react devDep).
@@ -41,5 +36,21 @@ export default withNextra({
4136
},
4237
images: {
4338
unoptimized: true
44-
}
39+
},
40+
async rewrites() {
41+
return [
42+
{
43+
source: '/ingest/static/:path*',
44+
destination: 'https://us-assets.i.posthog.com/static/:path*',
45+
},
46+
{
47+
source: '/ingest/:path*',
48+
destination: 'https://us.i.posthog.com/:path*',
49+
},
50+
{
51+
source: '/ingest/decide',
52+
destination: 'https://us.i.posthog.com/decide',
53+
},
54+
]
55+
},
4556
})

apps/docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"version": "0.0.1",
55
"scripts": {
66
"prebuild": "node ./scripts/generate-seo-files.mjs",
7-
"postbuild": "node ./scripts/verify-static-export.mjs && node ./scripts/verify-metadata.mjs",
7+
"postbuild": "node ./scripts/verify-metadata.mjs",
88
"dev": "next dev -p 3003",
99
"build": "next build",
1010
"start": "next start",

apps/docs/theme.config.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ const config: DocsThemeConfig = {
211211
// Load PostHog
212212
!function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.crossOrigin="anonymous",p.async=!0,p.src=s.api_host.replace(".i.posthog.com","-assets.i.posthog.com")+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="init capture register register_once register_for_session unregister unregister_for_session getFeatureFlag getFeatureFlagPayload isFeatureEnabled reloadFeatureFlags updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures on onFeatureFlags onSessionId getSurveys getActiveMatchingSurveys renderSurvey canRenderSurvey getNextSurveyStep identify setPersonProperties group resetGroups setPersonPropertiesForFlags resetPersonPropertiesForFlags setGroupPropertiesForFlags resetGroupPropertiesForFlags reset get_distinct_id getGroups get_session_id get_session_replay_url alias set_config startSessionRecording stopSessionRecording sessionRecordingStarted captureException loadToolbar get_property getSessionProperty createPersonProfile opt_in_capturing opt_out_capturing has_opted_in_capturing has_opted_out_capturing clear_opt_in_out_capturing debug".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]);
213213
posthog.init('${POSTHOG_KEY}',{
214-
api_host:'${POSTHOG_HOST}',
214+
api_host:'/ingest',
215+
ui_host:'${POSTHOG_HOST}',
215216
person_profiles:'identified_only',
216217
capture_pageview:true,
217218
capture_pageleave:true,

0 commit comments

Comments
 (0)