@posthog/wizard 1.22.0 → 1.23.0

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.
@@ -1,272 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getModernNextjsDocs = exports.getNextjsPagesRouterDocs = exports.getNextjsAppRouterDocs = void 0;
4
- const urls_1 = require("../utils/urls");
5
- const getNextjsAppRouterDocs = ({ host, language, }) => {
6
- return `
7
- ==============================
8
- FILE: PostHogProvider.${language === 'typescript' ? 'tsx' : 'jsx'} (put it somewhere where client files are, like the components folder)
9
- LOCATION: Wherever other providers are, or the components folder
10
- ==============================
11
- Changes:
12
- - Create a PostHogProvider component that will be imported into the layout file.
13
- - Make sure to include the defaults: '2025-05-24' option in the init call.
14
-
15
- Example:
16
- --------------------------------------------------
17
- "use client"
18
-
19
- import posthog from "posthog-js"
20
- import { PostHogProvider as PHProvider, usePostHog } from "posthog-js/react"
21
- import { Suspense, useEffect } from "react"
22
- import { usePathname, useSearchParams } from "next/navigation"
23
-
24
- export function PostHogProvider({ children }: { children: React.ReactNode }) {
25
- useEffect(() => {
26
- posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
27
- api_host: "/ingest",
28
- ui_host: "${(0, urls_1.getUiHostFromHost)(host)}",
29
- defaults: '2025-05-24',
30
- capture_exceptions: true, // This enables capturing exceptions using Error Tracking, set to false if you don't want this
31
- debug: process.env.NODE_ENV === "development",
32
- })
33
- }, [])
34
-
35
- return (
36
- <PHProvider client={posthog}>
37
- {children}
38
- </PHProvider>
39
- )
40
- }
41
- --------------------------------------------------
42
-
43
- ==============================
44
- FILE: layout.${language === 'typescript' ? 'tsx' : 'jsx'}
45
- LOCATION: Wherever the root layout is
46
- ==============================
47
- Changes:
48
- - Import the PostHogProvider from the providers file and wrap the app in it.
49
-
50
- Example:
51
- --------------------------------------------------
52
- // other imports
53
- import { PostHogProvider } from "LOCATION_OF_POSTHOG_PROVIDER"
54
-
55
- export default function RootLayout({ children }) {
56
- return (
57
- <html lang="en">
58
- <body>
59
- <PostHogProvider>
60
- {/* other providers */}
61
- {children}
62
- {/* other providers */}
63
- </PostHogProvider>
64
- </body>
65
- </html>
66
- )
67
- }
68
- --------------------------------------------------
69
-
70
- ==============================
71
- FILE: posthog.${language === 'typescript' ? 'ts' : 'js'}
72
- LOCATION: Wherever works best given the project structure
73
- ==============================
74
- Changes:
75
- - Initialize the PostHog Node.js client
76
-
77
- Example:
78
- --------------------------------------------------
79
- import { PostHog } from "posthog-node"
80
-
81
- // NOTE: This is a Node.js client, so you can use it for sending events from the server side to PostHog.
82
- export default function PostHogClient() {
83
- const posthogClient = new PostHog(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
84
- host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
85
- flushAt: 1,
86
- flushInterval: 0,
87
- })
88
- return posthogClient
89
- }
90
- --------------------------------------------------
91
-
92
- ==============================
93
- FILE: next.config.{js,ts,mjs,cjs}
94
- LOCATION: Wherever the root next config is
95
- ==============================
96
- Changes:
97
- - Add rewrites to the Next.js config to support PostHog, if there are existing rewrites, add the PostHog rewrites to them.
98
- - Add skipTrailingSlashRedirect to the Next.js config to support PostHog trailing slash API requests.
99
- - This can be of type js, ts, mjs, cjs etc. You should adapt the file according to what extension it uses, and if it does not exist yet use '.js'.
100
-
101
- Example:
102
- --------------------------------------------------
103
- const nextConfig = {
104
- // other config
105
- async rewrites() {
106
- return [
107
- {
108
- source: "/ingest/static/:path*",
109
- destination: "${(0, urls_1.getAssetHostFromHost)(host)}/static/:path*",
110
- },
111
- {
112
- source: "/ingest/:path*",
113
- destination: "${host}/:path*",
114
- },
115
- ];
116
- },
117
- // This is required to support PostHog trailing slash API requests
118
- skipTrailingSlashRedirect: true,
119
- }
120
- module.exports = nextConfig
121
- --------------------------------------------------`;
122
- };
123
- exports.getNextjsAppRouterDocs = getNextjsAppRouterDocs;
124
- const getNextjsPagesRouterDocs = ({ host, language, }) => {
125
- return `
126
- ==============================
127
- FILE: _app.${language === 'typescript' ? 'tsx' : 'jsx'}
128
- LOCATION: Wherever the root _app.${language === 'typescript' ? 'tsx' : 'jsx'} file is
129
- ==============================
130
- Changes:
131
- - Initialize PostHog in _app.js.
132
- - Wrap the application in PostHogProvider.
133
- - Make sure to include the defaults: '2025-05-24' option in the init call.
134
-
135
- Example:
136
- --------------------------------------------------
137
- import { useEffect } from "react"
138
- import posthog from "posthog-js"
139
- import { PostHogProvider } from "posthog-js/react"
140
-
141
- export default function App({ Component, pageProps }) {
142
- useEffect(() => {
143
- posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, {
144
- api_host: "/ingest",
145
- ui_host: "${(0, urls_1.getUiHostFromHost)(host)}",
146
- defaults: '2025-05-24',
147
- capture_exceptions: true, // This enables capturing exceptions using Error Tracking, set to false if you don't want this
148
- debug: process.env.NODE_ENV === "development",
149
- })
150
- }, [])
151
-
152
- return (
153
- <PostHogProvider client={posthog}>
154
- <Component {...pageProps} />
155
- </PostHogProvider>
156
- )
157
- }
158
- --------------------------------------------------
159
-
160
- ==============================
161
- FILE: posthog.${language === 'typescript' ? 'ts' : 'js'}
162
- LOCATION: Wherever works best given the project structure
163
- ==============================
164
- Changes:
165
- - Initialize the PostHog Node.js client
166
-
167
- Example:
168
- --------------------------------------------------
169
- import { PostHog } from "posthog-node"
170
-
171
- // NOTE: This is a Node.js client, so you can use it for sending events from the server side to PostHog.
172
- export default function PostHogClient() {
173
- const posthogClient = new PostHog(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
174
- host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
175
- flushAt: 1,
176
- flushInterval: 0,
177
- })
178
- return posthogClient
179
- }
180
- --------------------------------------------------
181
-
182
- ==============================
183
- FILE: next.config.{js,ts,mjs,cjs}
184
- LOCATION: Wherever the root next config is
185
- ==============================
186
- Changes:
187
- - Add rewrites to the Next.js config to support PostHog, if there are existing rewrites, add the PostHog rewrites to them.
188
- - Add skipTrailingSlashRedirect to the Next.js config to support PostHog trailing slash API requests.
189
- - This can be of type js, ts, mjs, cjs etc. You should adapt the file according to what extension it uses, and if it does not exist yet use '.js'.
190
-
191
- Example:
192
- --------------------------------------------------
193
- const nextConfig = {
194
- // other config
195
- async rewrites() {
196
- return [
197
- {
198
- source: "/ingest/static/:path*",
199
- destination: "${(0, urls_1.getAssetHostFromHost)(host)}/static/:path*",
200
- },
201
- {
202
- source: "/ingest/:path*",
203
- destination: "${host}/:path*",
204
- },
205
- ];
206
- },
207
- // This is required to support PostHog trailing slash API requests
208
- skipTrailingSlashRedirect: true,
209
- }
210
- module.exports = nextConfig
211
- --------------------------------------------------`;
212
- };
213
- exports.getNextjsPagesRouterDocs = getNextjsPagesRouterDocs;
214
- const getModernNextjsDocs = ({ host, language, }) => {
215
- return `
216
- ==============================
217
- FILE: instrumentation-client.${language === 'typescript' ? 'ts' : 'js'}
218
- LOCATION: in the root of the application or inside an src folder.
219
- ==============================
220
- Changes:
221
- - Create or update the instrumentation-client.${language === 'typescript' ? 'ts' : 'js'} file to use the PostHog client. If the file does not exist yet, create it.
222
- - Do *not* import instrumentation-client.${language === 'typescript' ? 'ts' : 'js'} in any other file; Next.js will automatically handle it.
223
- - Do not modify any other pages/components in the Next.js application; the PostHog client will be automatically initialized and handle all pageview tasks on its own.
224
- - Make sure to include the defaults: '2025-05-24' option in the init call.
225
-
226
- Example:
227
- --------------------------------------------------
228
-
229
- import posthog from "posthog-js"
230
-
231
- posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
232
- api_host: "/ingest",
233
- ui_host: "${(0, urls_1.getUiHostFromHost)(host)}",
234
- defaults: '2025-05-24',
235
- capture_exceptions: true, // This enables capturing exceptions using Error Tracking, set to false if you don't want this
236
- debug: process.env.NODE_ENV === "development",
237
- });
238
- --------------------------------------------------
239
-
240
- ==============================
241
- FILE: next.config.{js,ts,mjs,cjs}
242
- LOCATION: Wherever the root next config is
243
- ==============================
244
- Changes:
245
- - Add rewrites to the Next.js config to support PostHog, if there are existing rewrites, add the PostHog rewrites to them.
246
- - Add skipTrailingSlashRedirect to the Next.js config to support PostHog trailing slash API requests.
247
- - This can be of type js, ts, mjs, cjs etc. You should adapt the file according to what extension it uses, and if it does not exist yet use '.js'.
248
-
249
- Example:
250
- --------------------------------------------------
251
- const nextConfig = {
252
- // other config
253
- async rewrites() {
254
- return [
255
- {
256
- source: "/ingest/static/:path*",
257
- destination: "${(0, urls_1.getAssetHostFromHost)(host)}/static/:path*",
258
- },
259
- {
260
- source: "/ingest/:path*",
261
- destination: "${host}/:path*",
262
- },
263
- ];
264
- },
265
- // This is required to support PostHog trailing slash API requests
266
- skipTrailingSlashRedirect: true,
267
- }
268
- module.exports = nextConfig
269
- --------------------------------------------------`;
270
- };
271
- exports.getModernNextjsDocs = getModernNextjsDocs;
272
- //# sourceMappingURL=docs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"docs.js","sourceRoot":"","sources":["../../../src/nextjs/docs.ts"],"names":[],"mappings":";;;AAAA,wCAAwE;AAEjE,MAAM,sBAAsB,GAAG,CAAC,EACrC,IAAI,EACJ,QAAQ,GAIT,EAAE,EAAE;IACH,OAAO;;wBAGL,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KACtC;;;;;;;;;;;;;;;;;;;;kBAoBgB,IAAA,wBAAiB,EAAC,IAAI,CAAC;;;;;;;;;;;;;;;;eAgB1B,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;gBA2BxC,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAsC/B,IAAA,2BAAoB,EAAC,IAAI,CAAC;;;;wBAI1B,IAAI;;;;;;;;mDAQuB,CAAC;AACpD,CAAC,CAAC;AA7HW,QAAA,sBAAsB,0BA6HjC;AAEK,MAAM,wBAAwB,GAAG,CAAC,EACvC,IAAI,EACJ,QAAQ,GAIT,EAAE,EAAE;IACH,OAAO;;aAEI,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK;mCAElD,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KACtC;;;;;;;;;;;;;;;;;kBAiBgB,IAAA,wBAAiB,EAAC,IAAI,CAAC;;;;;;;;;;;;;;;;gBAgBzB,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAsC/B,IAAA,2BAAoB,EAAC,IAAI,CAAC;;;;wBAI1B,IAAI;;;;;;;;mDAQuB,CAAC;AACpD,CAAC,CAAC;AAhGW,QAAA,wBAAwB,4BAgGnC;AAEK,MAAM,mBAAmB,GAAG,CAAC,EAClC,IAAI,EACJ,QAAQ,GAIT,EAAE,EAAE;IACH,OAAO;;+BAEsB,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI;;;;gDAKlE,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IACrC;2CAEE,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IACrC;;;;;;;;;;;cAWY,IAAA,wBAAiB,EAAC,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;;;wBAwBb,IAAA,2BAAoB,EAAC,IAAI,CAAC;;;;wBAI1B,IAAI;;;;;;;;mDAQuB,CAAC;AACpD,CAAC,CAAC;AAlEW,QAAA,mBAAmB,uBAkE9B","sourcesContent":["import { getAssetHostFromHost, getUiHostFromHost } from '../utils/urls';\n\nexport const getNextjsAppRouterDocs = ({\n host,\n language,\n}: {\n host: string;\n language: 'typescript' | 'javascript';\n}) => {\n return `\n==============================\nFILE: PostHogProvider.${\n language === 'typescript' ? 'tsx' : 'jsx'\n } (put it somewhere where client files are, like the components folder)\nLOCATION: Wherever other providers are, or the components folder\n==============================\nChanges:\n- Create a PostHogProvider component that will be imported into the layout file.\n- Make sure to include the defaults: '2025-05-24' option in the init call.\n\nExample:\n--------------------------------------------------\n\"use client\"\n\nimport posthog from \"posthog-js\"\nimport { PostHogProvider as PHProvider, usePostHog } from \"posthog-js/react\"\nimport { Suspense, useEffect } from \"react\"\nimport { usePathname, useSearchParams } from \"next/navigation\"\n\nexport function PostHogProvider({ children }: { children: React.ReactNode }) {\n useEffect(() => {\n posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {\n api_host: \"/ingest\",\n ui_host: \"${getUiHostFromHost(host)}\",\n defaults: '2025-05-24',\n capture_exceptions: true, // This enables capturing exceptions using Error Tracking, set to false if you don't want this\n debug: process.env.NODE_ENV === \"development\",\n })\n }, [])\n\n return (\n <PHProvider client={posthog}>\n {children}\n </PHProvider>\n )\n}\n--------------------------------------------------\n\n==============================\nFILE: layout.${language === 'typescript' ? 'tsx' : 'jsx'}\nLOCATION: Wherever the root layout is\n==============================\nChanges:\n- Import the PostHogProvider from the providers file and wrap the app in it.\n\nExample:\n--------------------------------------------------\n// other imports\nimport { PostHogProvider } from \"LOCATION_OF_POSTHOG_PROVIDER\"\n\nexport default function RootLayout({ children }) {\n return (\n <html lang=\"en\">\n <body>\n <PostHogProvider>\n {/* other providers */}\n {children}\n {/* other providers */}\n </PostHogProvider>\n </body>\n </html>\n )\n}\n--------------------------------------------------\n\n==============================\nFILE: posthog.${language === 'typescript' ? 'ts' : 'js'}\nLOCATION: Wherever works best given the project structure\n==============================\nChanges:\n- Initialize the PostHog Node.js client\n\nExample:\n--------------------------------------------------\nimport { PostHog } from \"posthog-node\"\n\n// NOTE: This is a Node.js client, so you can use it for sending events from the server side to PostHog.\nexport default function PostHogClient() {\n const posthogClient = new PostHog(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {\n host: process.env.NEXT_PUBLIC_POSTHOG_HOST,\n flushAt: 1,\n flushInterval: 0,\n })\n return posthogClient\n}\n--------------------------------------------------\n\n==============================\nFILE: next.config.{js,ts,mjs,cjs}\nLOCATION: Wherever the root next config is\n==============================\nChanges:\n- Add rewrites to the Next.js config to support PostHog, if there are existing rewrites, add the PostHog rewrites to them.\n- Add skipTrailingSlashRedirect to the Next.js config to support PostHog trailing slash API requests.\n- This can be of type js, ts, mjs, cjs etc. You should adapt the file according to what extension it uses, and if it does not exist yet use '.js'.\n\nExample:\n--------------------------------------------------\nconst nextConfig = {\n // other config\n async rewrites() {\n return [\n {\n source: \"/ingest/static/:path*\",\n destination: \"${getAssetHostFromHost(host)}/static/:path*\",\n },\n {\n source: \"/ingest/:path*\",\n destination: \"${host}/:path*\",\n },\n ];\n },\n // This is required to support PostHog trailing slash API requests\n skipTrailingSlashRedirect: true,\n}\nmodule.exports = nextConfig\n--------------------------------------------------`;\n};\n\nexport const getNextjsPagesRouterDocs = ({\n host,\n language,\n}: {\n host: string;\n language: 'typescript' | 'javascript';\n}) => {\n return `\n==============================\nFILE: _app.${language === 'typescript' ? 'tsx' : 'jsx'}\nLOCATION: Wherever the root _app.${\n language === 'typescript' ? 'tsx' : 'jsx'\n } file is\n==============================\nChanges:\n- Initialize PostHog in _app.js.\n- Wrap the application in PostHogProvider.\n- Make sure to include the defaults: '2025-05-24' option in the init call.\n\nExample:\n--------------------------------------------------\nimport { useEffect } from \"react\"\nimport posthog from \"posthog-js\"\nimport { PostHogProvider } from \"posthog-js/react\"\n\nexport default function App({ Component, pageProps }) {\n useEffect(() => {\n posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, {\n api_host: \"/ingest\",\n ui_host: \"${getUiHostFromHost(host)}\",\n defaults: '2025-05-24',\n capture_exceptions: true, // This enables capturing exceptions using Error Tracking, set to false if you don't want this\n debug: process.env.NODE_ENV === \"development\",\n })\n }, [])\n\n return (\n <PostHogProvider client={posthog}>\n <Component {...pageProps} />\n </PostHogProvider>\n )\n}\n--------------------------------------------------\n\n==============================\nFILE: posthog.${language === 'typescript' ? 'ts' : 'js'}\nLOCATION: Wherever works best given the project structure\n==============================\nChanges:\n- Initialize the PostHog Node.js client\n\nExample:\n--------------------------------------------------\nimport { PostHog } from \"posthog-node\"\n\n// NOTE: This is a Node.js client, so you can use it for sending events from the server side to PostHog.\nexport default function PostHogClient() {\n const posthogClient = new PostHog(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {\n host: process.env.NEXT_PUBLIC_POSTHOG_HOST,\n flushAt: 1,\n flushInterval: 0,\n })\n return posthogClient\n}\n--------------------------------------------------\n\n==============================\nFILE: next.config.{js,ts,mjs,cjs}\nLOCATION: Wherever the root next config is\n==============================\nChanges:\n- Add rewrites to the Next.js config to support PostHog, if there are existing rewrites, add the PostHog rewrites to them.\n- Add skipTrailingSlashRedirect to the Next.js config to support PostHog trailing slash API requests.\n- This can be of type js, ts, mjs, cjs etc. You should adapt the file according to what extension it uses, and if it does not exist yet use '.js'.\n\nExample:\n--------------------------------------------------\nconst nextConfig = {\n // other config\n async rewrites() {\n return [\n {\n source: \"/ingest/static/:path*\",\n destination: \"${getAssetHostFromHost(host)}/static/:path*\",\n },\n {\n source: \"/ingest/:path*\",\n destination: \"${host}/:path*\",\n },\n ];\n },\n // This is required to support PostHog trailing slash API requests\n skipTrailingSlashRedirect: true,\n}\nmodule.exports = nextConfig\n--------------------------------------------------`;\n};\n\nexport const getModernNextjsDocs = ({\n host,\n language,\n}: {\n host: string;\n language: 'typescript' | 'javascript';\n}) => {\n return `\n==============================\nFILE: instrumentation-client.${language === 'typescript' ? 'ts' : 'js'}\nLOCATION: in the root of the application or inside an src folder.\n==============================\nChanges:\n- Create or update the instrumentation-client.${\n language === 'typescript' ? 'ts' : 'js'\n } file to use the PostHog client. If the file does not exist yet, create it.\n- Do *not* import instrumentation-client.${\n language === 'typescript' ? 'ts' : 'js'\n } in any other file; Next.js will automatically handle it.\n- Do not modify any other pages/components in the Next.js application; the PostHog client will be automatically initialized and handle all pageview tasks on its own.\n- Make sure to include the defaults: '2025-05-24' option in the init call.\n\nExample:\n--------------------------------------------------\n\nimport posthog from \"posthog-js\"\n\nposthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {\n api_host: \"/ingest\",\n ui_host: \"${getUiHostFromHost(host)}\",\n defaults: '2025-05-24',\n capture_exceptions: true, // This enables capturing exceptions using Error Tracking, set to false if you don't want this\n debug: process.env.NODE_ENV === \"development\",\n});\n--------------------------------------------------\n\n==============================\nFILE: next.config.{js,ts,mjs,cjs}\nLOCATION: Wherever the root next config is\n==============================\nChanges:\n- Add rewrites to the Next.js config to support PostHog, if there are existing rewrites, add the PostHog rewrites to them.\n- Add skipTrailingSlashRedirect to the Next.js config to support PostHog trailing slash API requests.\n- This can be of type js, ts, mjs, cjs etc. You should adapt the file according to what extension it uses, and if it does not exist yet use '.js'.\n\nExample:\n--------------------------------------------------\nconst nextConfig = {\n // other config\n async rewrites() {\n return [\n {\n source: \"/ingest/static/:path*\",\n destination: \"${getAssetHostFromHost(host)}/static/:path*\",\n },\n {\n source: \"/ingest/:path*\",\n destination: \"${host}/:path*\",\n },\n ];\n },\n // This is required to support PostHog trailing slash API requests\n skipTrailingSlashRedirect: true,\n}\nmodule.exports = nextConfig\n--------------------------------------------------`;\n};\n"]}
@@ -1,2 +0,0 @@
1
- import { WizardOptions } from '../utils/types';
2
- export declare function runEventSetupWizard(options: WizardOptions): Promise<void>;