@posthog/wizard 1.8.6 → 1.9.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.
- package/README.md +81 -41
- package/dist/bin.js +50 -0
- package/dist/bin.js.map +1 -1
- package/dist/src/lib/constants.d.ts +1 -1
- package/dist/src/lib/constants.js +1 -1
- package/dist/src/lib/constants.js.map +1 -1
- package/dist/src/nextjs/docs.js +6 -6
- package/dist/src/nextjs/docs.js.map +1 -1
- package/dist/src/nextjs/event-setup.d.ts +2 -0
- package/dist/src/nextjs/event-setup.js +388 -0
- package/dist/src/nextjs/event-setup.js.map +1 -0
- package/dist/src/nextjs/nextjs-wizard.js +1 -0
- package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
- package/dist/src/nextjs/utils.js +1 -0
- package/dist/src/nextjs/utils.js.map +1 -1
- package/dist/src/utils/clack-utils.js +5 -3
- package/dist/src/utils/clack-utils.js.map +1 -1
- package/dist/src/utils/query.d.ts +3 -2
- package/dist/src/utils/query.js +28 -1
- package/dist/src/utils/query.js.map +1 -1
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
5
|
> **⚠️ Experimental:** This wizard is still in an experimental phase. If you
|
|
6
|
-
> have any feedback, please drop an email to **joshua** [at] **posthog** [dot]
|
|
6
|
+
> have any feedback, please drop an email to **joshua** [at] **posthog** [dot] >
|
|
7
7
|
> **com**.
|
|
8
8
|
|
|
9
9
|
<h1>PostHog wizard ✨</h1>
|
|
@@ -17,13 +17,14 @@ To use the wizard, you can run it directly using:
|
|
|
17
17
|
npx @posthog/wizard
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
Currently the wizard can be used for **React, NextJS, Svelte, Astro and React
|
|
21
|
-
projects. If you have other integrations you would like the wizard to
|
|
22
|
-
please open a [GitHub issue](https://github.com/posthog/wizard/issues)!
|
|
20
|
+
Currently the wizard can be used for **React, NextJS, Svelte, Astro and React
|
|
21
|
+
Native** projects. If you have other integrations you would like the wizard to
|
|
22
|
+
support, please open a [GitHub issue](https://github.com/posthog/wizard/issues)!
|
|
23
23
|
|
|
24
24
|
## MCP Commands
|
|
25
25
|
|
|
26
|
-
The wizard also includes commands for managing PostHog MCP (Model Context
|
|
26
|
+
The wizard also includes commands for managing PostHog MCP (Model Context
|
|
27
|
+
Protocol) servers:
|
|
27
28
|
|
|
28
29
|
```bash
|
|
29
30
|
# Install PostHog MCP server to supported clients
|
|
@@ -37,17 +38,17 @@ npx @posthog/wizard mcp remove
|
|
|
37
38
|
|
|
38
39
|
The following CLI arguments are available:
|
|
39
40
|
|
|
40
|
-
| Option | Description
|
|
41
|
-
| ----------------- |
|
|
42
|
-
| `--help` | Show help
|
|
43
|
-
| `--version` | Show version number
|
|
44
|
-
| `--debug` | Enable verbose logging
|
|
45
|
-
| `--region` | PostHog cloud region (when not specified, prompts for selection)
|
|
46
|
-
| `--default` | Use default options for all prompts
|
|
47
|
-
| `--signup` | Create a new PostHog account during setup
|
|
48
|
-
| `--integration` | Integration to set up
|
|
49
|
-
| `--force-install` | Force install packages even if peer dependency checks fail
|
|
50
|
-
| `--install-dir` | Directory to install PostHog in
|
|
41
|
+
| Option | Description | Type | Default | Choices | Environment Variable |
|
|
42
|
+
| ----------------- | ---------------------------------------------------------------- | ------- | ------- | ---------------------------------------------------- | ------------------------------ |
|
|
43
|
+
| `--help` | Show help | boolean | | | |
|
|
44
|
+
| `--version` | Show version number | boolean | | | |
|
|
45
|
+
| `--debug` | Enable verbose logging | boolean | `false` | | `POSTHOG_WIZARD_DEBUG` |
|
|
46
|
+
| `--region` | PostHog cloud region (when not specified, prompts for selection) | string | | "us", "eu" | `POSTHOG_WIZARD_REGION` |
|
|
47
|
+
| `--default` | Use default options for all prompts | boolean | `true` | | `POSTHOG_WIZARD_DEFAULT` |
|
|
48
|
+
| `--signup` | Create a new PostHog account during setup | boolean | `false` | | `POSTHOG_WIZARD_SIGNUP` |
|
|
49
|
+
| `--integration` | Integration to set up | string | | "nextjs", "astro", "react", "svelte", "react-native" | |
|
|
50
|
+
| `--force-install` | Force install packages even if peer dependency checks fail | boolean | `false` | | `POSTHOG_WIZARD_FORCE_INSTALL` |
|
|
51
|
+
| `--install-dir` | Directory to install PostHog in | string | | | `POSTHOG_WIZARD_INSTALL_DIR` |
|
|
51
52
|
|
|
52
53
|
> Note: A large amount of the scaffolding for this came from the amazing Sentry
|
|
53
54
|
> wizard, which you can find [here](https://github.com/getsentry/sentry-wizard)
|
|
@@ -55,43 +56,65 @@ The following CLI arguments are available:
|
|
|
55
56
|
|
|
56
57
|
# Steal this code
|
|
57
58
|
|
|
58
|
-
While the wizard works great on its own, we also find the approach used by this
|
|
59
|
+
While the wizard works great on its own, we also find the approach used by this
|
|
60
|
+
project is
|
|
61
|
+
[a powerful way to improve AI agent coding sessions](https://posthog.com/blog/envoy-wizard-llm-agent).
|
|
62
|
+
Agents can run CLI tools, which means that conventional code like this can
|
|
63
|
+
participate in the AI revolution as well – with all the benefits and control
|
|
64
|
+
that conventional code implies.
|
|
59
65
|
|
|
60
|
-
If you want to use this code as a starting place for your own project, here's a
|
|
66
|
+
If you want to use this code as a starting place for your own project, here's a
|
|
67
|
+
quick explainer on its structure.
|
|
61
68
|
|
|
62
69
|
## Entrypoint: `run.ts`
|
|
63
70
|
|
|
64
|
-
The entrypoint for this tool is `run.ts`. Use this file to interpret arguments
|
|
71
|
+
The entrypoint for this tool is `run.ts`. Use this file to interpret arguments
|
|
72
|
+
and set up the general flow of the application.
|
|
65
73
|
|
|
66
74
|
## Analytics
|
|
67
75
|
|
|
68
|
-
Did you know you can capture PostHog events even for smaller, supporting
|
|
76
|
+
Did you know you can capture PostHog events even for smaller, supporting
|
|
77
|
+
products like a command line tool? `src/utils/analytics.ts` is a great example
|
|
78
|
+
of how to do it.
|
|
69
79
|
|
|
70
|
-
This file wraps `posthog-node` with some convenience functions to set up an
|
|
80
|
+
This file wraps `posthog-node` with some convenience functions to set up an
|
|
81
|
+
analytics session and log events. We can see the usage and outcomes of this
|
|
82
|
+
wizard alongside all of our other PostHog product data, and this is very
|
|
83
|
+
powerful. For example: we could show in-product surveys to people who have used
|
|
84
|
+
the wizard to improve the experience.
|
|
71
85
|
|
|
72
86
|
## Leave rules behind
|
|
73
87
|
|
|
74
|
-
Supporting agent sessions after we leave is important. There are plenty of ways
|
|
88
|
+
Supporting agent sessions after we leave is important. There are plenty of ways
|
|
89
|
+
to break or misconfigure PostHog, so guarding against this is key.
|
|
75
90
|
|
|
76
|
-
`src/utils/rules/add-editor-rules.ts` demonstrates how to dynamically construct
|
|
91
|
+
`src/utils/rules/add-editor-rules.ts` demonstrates how to dynamically construct
|
|
92
|
+
rules files and store them in the project's `.cursor/rules` directory.
|
|
77
93
|
|
|
78
94
|
## Prompts and LLM interactions
|
|
79
95
|
|
|
80
|
-
LLM agent sessions are
|
|
96
|
+
LLM agent sessions are _anti-deterministic_: really, anything can happen.
|
|
81
97
|
|
|
82
|
-
But using LLMs for code generation is really advantageous: they can interpret
|
|
98
|
+
But using LLMs for code generation is really advantageous: they can interpret
|
|
99
|
+
existing code at scale and then modify it reliably.
|
|
83
100
|
|
|
84
|
-
|
|
101
|
+
_If_ they are well prompted.
|
|
85
102
|
|
|
86
|
-
`src/lib/prompts.ts` demonstrates how to wrap a deterministic fence around a
|
|
103
|
+
`src/lib/prompts.ts` demonstrates how to wrap a deterministic fence around a
|
|
104
|
+
chaotic process. Every wizard session gets the same prompt, tailored to the
|
|
105
|
+
specific files in the project.
|
|
87
106
|
|
|
88
|
-
These prompts are channeled using `src/utils/query.ts` to an LLM interface we
|
|
107
|
+
These prompts are channeled using `src/utils/query.ts` to an LLM interface we
|
|
108
|
+
host. This gives us more control: we can be certain of the model version and
|
|
109
|
+
provider which interpret the prompts and modify the files. This way, we can find
|
|
110
|
+
the right tools for the job and again, apply them consistently.
|
|
89
111
|
|
|
90
112
|
This also allows us to pick up the bill on behalf of our customers.
|
|
91
113
|
|
|
92
|
-
When we make improvements to this process, these are available instantly to all
|
|
114
|
+
When we make improvements to this process, these are available instantly to all
|
|
115
|
+
users of the wizard, no training delays or other ambiguity.
|
|
93
116
|
|
|
94
|
-
##
|
|
117
|
+
## Running locally
|
|
95
118
|
|
|
96
119
|
Run:
|
|
97
120
|
|
|
@@ -99,35 +122,52 @@ Run:
|
|
|
99
122
|
pnpm try --install-dir=[a path]
|
|
100
123
|
```
|
|
101
124
|
|
|
102
|
-
|
|
103
125
|
To build and use the tool locally:
|
|
104
126
|
|
|
127
|
+
```bash
|
|
128
|
+
bin/build
|
|
105
129
|
```
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
130
|
+
|
|
131
|
+
This compiles the TypeScript code and prepares the `dist` directory. Run this
|
|
132
|
+
command any time you make changes to the wizard's source code.
|
|
109
133
|
|
|
110
134
|
```bash
|
|
111
135
|
pnpm link --global
|
|
112
136
|
```
|
|
113
|
-
This command makes your local version of the wizard available system-wide. You generally only need to do this once.
|
|
114
137
|
|
|
115
|
-
|
|
138
|
+
This command makes your local version of the wizard available system-wide. You
|
|
139
|
+
generally only need to do this once.
|
|
140
|
+
|
|
141
|
+
Then:
|
|
116
142
|
|
|
117
143
|
```bash
|
|
118
144
|
wizard [options]
|
|
119
145
|
```
|
|
146
|
+
|
|
120
147
|
The wizard will execute your last build.
|
|
121
148
|
|
|
122
|
-
##
|
|
149
|
+
## Testing
|
|
123
150
|
|
|
124
|
-
To
|
|
151
|
+
To run unit tests, run:
|
|
125
152
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
153
|
+
```bash
|
|
154
|
+
bin/test
|
|
155
|
+
```
|
|
129
156
|
|
|
157
|
+
To run E2E tests run:
|
|
130
158
|
|
|
159
|
+
```bash
|
|
160
|
+
bin/test-e2e
|
|
161
|
+
```
|
|
131
162
|
|
|
163
|
+
E2E tests are a bit more complicated to create and adjust due to to their mocked
|
|
164
|
+
LLM calls. See the `e2e-tests/README.md` for more information.
|
|
132
165
|
|
|
166
|
+
## Publishing your tool
|
|
133
167
|
|
|
168
|
+
To make your version of a tool usable with a one-line `npx` command:
|
|
169
|
+
|
|
170
|
+
1. Edit `package.json`, especially details like `name`, `version`
|
|
171
|
+
2. Run [`npm publish`](https://docs.npmjs.com/cli/v7/commands/npm-publish) from
|
|
172
|
+
your project directory
|
|
173
|
+
3. Now you can run it with `npx yourpackagename`
|
package/dist/bin.js
CHANGED
|
@@ -17,6 +17,22 @@ if (!(0, semver_1.satisfies)(process.version, NODE_VERSION_RANGE)) {
|
|
|
17
17
|
}
|
|
18
18
|
const mcp_1 = require("./src/mcp");
|
|
19
19
|
const run_1 = require("./src/run");
|
|
20
|
+
const event_setup_1 = require("./src/nextjs/event-setup");
|
|
21
|
+
const environment_1 = require("./src/utils/environment");
|
|
22
|
+
const path_1 = __importDefault(require("path"));
|
|
23
|
+
if (process.env.NODE_ENV === 'test') {
|
|
24
|
+
void (async () => {
|
|
25
|
+
try {
|
|
26
|
+
const { server } = await import('./e2e-tests/mocks/server.js');
|
|
27
|
+
server.listen({
|
|
28
|
+
onUnhandledRequest: 'bypass',
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
// Mock server import failed - this can happen during non-E2E tests
|
|
33
|
+
}
|
|
34
|
+
})();
|
|
35
|
+
}
|
|
20
36
|
(0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
|
|
21
37
|
.env('POSTHOG_WIZARD')
|
|
22
38
|
// global options
|
|
@@ -62,6 +78,40 @@ const run_1 = require("./src/run");
|
|
|
62
78
|
}, (argv) => {
|
|
63
79
|
const options = { ...argv };
|
|
64
80
|
void (0, run_1.runWizard)(options);
|
|
81
|
+
})
|
|
82
|
+
.command('event-setup', 'Run the event setup wizard', (yargs) => {
|
|
83
|
+
return yargs.options({
|
|
84
|
+
'install-dir': {
|
|
85
|
+
describe: 'Directory to run the wizard in\nenv: POSTHOG_WIZARD_INSTALL_DIR',
|
|
86
|
+
type: 'string',
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
}, (argv) => {
|
|
90
|
+
const finalArgs = {
|
|
91
|
+
...argv,
|
|
92
|
+
...(0, environment_1.readEnvironment)(),
|
|
93
|
+
};
|
|
94
|
+
let resolvedInstallDir;
|
|
95
|
+
if (finalArgs.installDir) {
|
|
96
|
+
if (path_1.default.isAbsolute(finalArgs.installDir)) {
|
|
97
|
+
resolvedInstallDir = finalArgs.installDir;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
resolvedInstallDir = path_1.default.join(process.cwd(), finalArgs.installDir);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
resolvedInstallDir = process.cwd();
|
|
105
|
+
}
|
|
106
|
+
const wizardOptions = {
|
|
107
|
+
debug: finalArgs.debug ?? false,
|
|
108
|
+
installDir: resolvedInstallDir,
|
|
109
|
+
cloudRegion: finalArgs.region,
|
|
110
|
+
default: finalArgs.default ?? false,
|
|
111
|
+
signup: finalArgs.signup ?? false,
|
|
112
|
+
forceInstall: false,
|
|
113
|
+
};
|
|
114
|
+
void (0, event_setup_1.runEventSetupWizard)(wizardOptions);
|
|
65
115
|
})
|
|
66
116
|
.command('mcp <command>', 'MCP server management commands', (yargs) => {
|
|
67
117
|
return yargs
|
package/dist/bin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../bin.ts"],"names":[],"mappings":";;;;;;AACA,mCAAmC;AACnC,iDAA0C;AAE1C,kDAA0B;AAC1B,2CAAwC;AAExC,MAAM,kBAAkB,GAAG,WAAW,CAAC;AAEvC,iFAAiF;AACjF,+BAA+B;AAC/B,IAAI,CAAC,IAAA,kBAAS,EAAC,OAAO,CAAC,OAAO,EAAE,kBAAkB,CAAC,EAAE,CAAC;IACpD,IAAA,aAAG,EACD,mCAAmC,kBAAkB,2BAA2B,OAAO,CAAC,OAAO,wCAAwC,CACxI,CAAC;IACF,OA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;IAC3B,CAAC,EACD,GAAG,EAAE;QACH,KAAK,IAAA,kBAAY,GAAE,CAAC;IACtB,CAAC,CACF;SACA,aAAa,CAAC,CAAC,EAAE,+CAA+C,CAAC;SACjE,IAAI,EAAE,CAAC;AACZ,CAAC,CAAC;KACD,IAAI,EAAE;KACN,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC;KAClB,OAAO,EAAE;KACT,KAAK,CAAC,SAAS,EAAE,GAAG,CAAC;KACrB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,eAAK,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC","sourcesContent":["#!/usr/bin/env node\nimport { satisfies } from 'semver';\nimport { red } from './src/utils/logging';\n\nimport yargs from 'yargs';\nimport { hideBin } from 'yargs/helpers';\n\nconst NODE_VERSION_RANGE = '>=18.17.0';\n\n// Have to run this above the other imports because they are importing clack that\n// has the problematic imports.\nif (!satisfies(process.version, NODE_VERSION_RANGE)) {\n red(\n `PostHog wizard requires Node.js ${NODE_VERSION_RANGE}. You are using Node.js ${process.version}. Please upgrade your Node.js version.`,\n );\n process.exit(1);\n}\n\nimport { runMCPInstall, runMCPRemove } from './src/mcp';\nimport type { CloudRegion, WizardOptions } from './src/utils/types';\nimport { runWizard } from './src/run';\nimport { runEventSetupWizard } from './src/nextjs/event-setup';\nimport { readEnvironment } from './src/utils/environment';\nimport path from 'path';\n\nif (process.env.NODE_ENV === 'test') {\n void (async () => {\n try {\n const { server } = await import('./e2e-tests/mocks/server.js');\n server.listen({\n onUnhandledRequest: 'bypass',\n });\n } catch (error) {\n // Mock server import failed - this can happen during non-E2E tests\n }\n })();\n}\n\nyargs(hideBin(process.argv))\n .env('POSTHOG_WIZARD')\n // global options\n .options({\n debug: {\n default: false,\n describe: 'Enable verbose logging\\nenv: POSTHOG_WIZARD_DEBUG',\n type: 'boolean',\n },\n region: {\n describe: 'PostHog cloud region\\nenv: POSTHOG_WIZARD_REGION',\n choices: ['us', 'eu'],\n type: 'string',\n },\n default: {\n default: true,\n describe:\n 'Use default options for all prompts\\nenv: POSTHOG_WIZARD_DEFAULT',\n type: 'boolean',\n },\n signup: {\n default: false,\n describe:\n 'Create a new PostHog account during setup\\nenv: POSTHOG_WIZARD_SIGNUP',\n type: 'boolean',\n },\n })\n .command(\n ['$0'],\n 'Run the PostHog setup wizard',\n (yargs) => {\n return yargs.options({\n 'force-install': {\n default: false,\n describe:\n 'Force install packages even if peer dependency checks fail\\nenv: POSTHOG_WIZARD_FORCE_INSTALL',\n type: 'boolean',\n },\n 'install-dir': {\n describe:\n 'Directory to install PostHog in\\nenv: POSTHOG_WIZARD_INSTALL_DIR',\n type: 'string',\n },\n integration: {\n describe: 'Integration to set up',\n choices: ['nextjs', 'astro', 'react', 'svelte', 'react-native'],\n type: 'string',\n },\n });\n },\n (argv) => {\n const options = { ...argv };\n void runWizard(options as unknown as WizardOptions);\n },\n )\n .command(\n 'event-setup',\n 'Run the event setup wizard',\n (yargs) => {\n return yargs.options({\n 'install-dir': {\n describe:\n 'Directory to run the wizard in\\nenv: POSTHOG_WIZARD_INSTALL_DIR',\n type: 'string',\n },\n });\n },\n (argv) => {\n const finalArgs = {\n ...argv,\n ...readEnvironment(),\n } as any;\n\n let resolvedInstallDir: string;\n if (finalArgs.installDir) {\n if (path.isAbsolute(finalArgs.installDir)) {\n resolvedInstallDir = finalArgs.installDir;\n } else {\n resolvedInstallDir = path.join(process.cwd(), finalArgs.installDir);\n }\n } else {\n resolvedInstallDir = process.cwd();\n }\n\n const wizardOptions: WizardOptions = {\n debug: finalArgs.debug ?? false,\n installDir: resolvedInstallDir,\n cloudRegion: finalArgs.region as CloudRegion | undefined,\n default: finalArgs.default ?? false,\n signup: finalArgs.signup ?? false,\n forceInstall: false,\n };\n\n void runEventSetupWizard(wizardOptions);\n },\n )\n .command('mcp <command>', 'MCP server management commands', (yargs) => {\n return yargs\n .command(\n 'add',\n 'Install PostHog MCP server to supported clients',\n (yargs) => {\n return yargs.options({});\n },\n (argv) => {\n const options = { ...argv };\n void runMCPInstall(\n options as unknown as { signup: boolean; region?: CloudRegion },\n );\n },\n )\n .command(\n 'remove',\n 'Remove PostHog MCP server from supported clients',\n (yargs) => {\n return yargs.options({});\n },\n () => {\n void runMCPRemove();\n },\n )\n .demandCommand(1, 'You must specify a subcommand (add or remove)')\n .help();\n })\n .help()\n .alias('help', 'h')\n .version()\n .alias('version', 'v')\n .wrap(process.stdout.isTTY ? yargs.terminalWidth() : 80).argv;\n"]}
|
|
@@ -15,7 +15,7 @@ export interface Args {
|
|
|
15
15
|
debug: boolean;
|
|
16
16
|
integration: Integration;
|
|
17
17
|
}
|
|
18
|
-
export declare const IS_DEV
|
|
18
|
+
export declare const IS_DEV: boolean;
|
|
19
19
|
export declare const DEBUG = false;
|
|
20
20
|
export declare const DEFAULT_URL: string;
|
|
21
21
|
export declare const ISSUES_URL = "https://github.com/posthog/wizard/issues";
|
|
@@ -33,7 +33,7 @@ function getIntegrationChoices() {
|
|
|
33
33
|
value: type,
|
|
34
34
|
}));
|
|
35
35
|
}
|
|
36
|
-
exports.IS_DEV =
|
|
36
|
+
exports.IS_DEV = ['test', 'development'].includes(process.env.NODE_ENV ?? '');
|
|
37
37
|
exports.DEBUG = false;
|
|
38
38
|
exports.DEFAULT_URL = exports.IS_DEV
|
|
39
39
|
? 'http://localhost:8010'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/lib/constants.ts"],"names":[],"mappings":";;;AAQA,8DAeC;AAOD,sDAKC;AAnCD,IAAY,WAMX;AAND,WAAY,WAAW;IACrB,gCAAiB,CAAA;IACjB,8BAAe,CAAA;IACf,gCAAiB,CAAA;IACjB,2CAA4B,CAAA;IAC5B,8BAAe,CAAA;AACjB,CAAC,EANW,WAAW,2BAAX,WAAW,QAMtB;AAED,SAAgB,yBAAyB,CAAC,IAAY;IACpD,QAAQ,IAAI,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AO,OAAO,CAAC;QACjB;YACE,MAAM,IAAI,KAAK,CAAC,uBAAuB,IAAI,EAAE,CAAC,CAAC;IACnD,CAAC;AACH,CAAC;AAOD,SAAgB,qBAAqB;IACnC,OAAO,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC;QACrD,IAAI,EAAE,yBAAyB,CAAC,IAAI,CAAC;QACrC,KAAK,EAAE,IAAI;KACZ,CAAC,CAAC,CAAC;AACN,CAAC;AAOY,QAAA,MAAM,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,QAAQ,CACpD,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,EAAE,CAC3B,CAAC;AAEW,QAAA,KAAK,GAAG,KAAK,CAAC;AAEd,QAAA,WAAW,GAAG,cAAM;IAC/B,CAAC,CAAC,uBAAuB;IACzB,CAAC,CAAC,wBAAwB,CAAC;AAChB,QAAA,UAAU,GAAG,0CAA0C,CAAC;AACxD,QAAA,gBAAgB,GAAG,cAAM;IACpC,CAAC,CAAC,uBAAuB;IACzB,CAAC,CAAC,0BAA0B,CAAC;AAClB,QAAA,0CAA0C,GAAG,gBAAgB,CAAC;AAC9D,QAAA,kBAAkB,GAAG,gCAAgC,CAAC;AACtD,QAAA,qBAAqB,GAAG,gCAAgC,CAAC","sourcesContent":["export enum Integration {\n nextjs = 'nextjs',\n react = 'react',\n svelte = 'svelte',\n reactNative = 'react-native',\n astro = 'astro',\n}\n\nexport function getIntegrationDescription(type: string): string {\n switch (type) {\n case Integration.nextjs:\n return 'Next.js';\n case Integration.react:\n return 'React';\n case Integration.reactNative:\n return 'React Native';\n case Integration.svelte:\n return 'Svelte';\n case Integration.astro:\n return 'Astro';\n default:\n throw new Error(`Unknown integration ${type}`);\n }\n}\n\ntype IntegrationChoice = {\n name: string;\n value: string;\n};\n\nexport function getIntegrationChoices(): IntegrationChoice[] {\n return Object.keys(Integration).map((type: string) => ({\n name: getIntegrationDescription(type),\n value: type,\n }));\n}\n\nexport interface Args {\n debug: boolean;\n integration: Integration;\n}\n\nexport const IS_DEV = ['test', 'development'].includes(\n process.env.NODE_ENV ?? '',\n);\n\nexport const DEBUG = false;\n\nexport const DEFAULT_URL = IS_DEV\n ? 'http://localhost:8010'\n : 'https://us.posthog.com';\nexport const ISSUES_URL = 'https://github.com/posthog/wizard/issues';\nexport const DEFAULT_HOST_URL = IS_DEV\n ? 'http://localhost:8010'\n : 'https://us.i.posthog.com';\nexport const ANALYTICS_POSTHOG_PUBLIC_PROJECT_WRITE_KEY = 'sTMFPsFhdP1Ssg';\nexport const ANALYTICS_HOST_URL = 'https://internal-t.posthog.com';\nexport const DUMMY_PROJECT_API_KEY = '_YOUR_POSTHOG_PROJECT_API_KEY_';\n"]}
|
package/dist/src/nextjs/docs.js
CHANGED
|
@@ -113,8 +113,8 @@ const nextConfig = {
|
|
|
113
113
|
destination: "${host}/:path*",
|
|
114
114
|
},
|
|
115
115
|
{
|
|
116
|
-
source: "/ingest/
|
|
117
|
-
destination: "${host}/
|
|
116
|
+
source: "/ingest/flags",
|
|
117
|
+
destination: "${host}/flags",
|
|
118
118
|
},
|
|
119
119
|
];
|
|
120
120
|
},
|
|
@@ -207,8 +207,8 @@ const nextConfig = {
|
|
|
207
207
|
destination: "${host}/:path*",
|
|
208
208
|
},
|
|
209
209
|
{
|
|
210
|
-
source: "/ingest/
|
|
211
|
-
destination: "${host}/
|
|
210
|
+
source: "/ingest/flags",
|
|
211
|
+
destination: "${host}/flags",
|
|
212
212
|
},
|
|
213
213
|
];
|
|
214
214
|
},
|
|
@@ -269,8 +269,8 @@ const nextConfig = {
|
|
|
269
269
|
destination: "${host}/:path*",
|
|
270
270
|
},
|
|
271
271
|
{
|
|
272
|
-
source: "/ingest/
|
|
273
|
-
destination: "${host}/
|
|
272
|
+
source: "/ingest/flags",
|
|
273
|
+
destination: "${host}/flags",
|
|
274
274
|
},
|
|
275
275
|
];
|
|
276
276
|
},
|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,IAAI;;;;wBAIJ,IAAI;;;;;;;;mDAQuB,CAAC;AACpD,CAAC,CAAC;AApGW,QAAA,wBAAwB,4BAoGnC;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;;;;wBAIJ,IAAI;;;;;;;;mDAQuB,CAAC;AACpD,CAAC,CAAC;AAtEW,QAAA,mBAAmB,uBAsE9B","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 source: \"/ingest/decide\",\n destination: \"${host}/decide\",\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 source: \"/ingest/decide\",\n destination: \"${host}/decide\",\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 source: \"/ingest/decide\",\n destination: \"${host}/decide\",\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
|
+
{"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;;;;wBAIJ,IAAI;;;;;;;;mDAQuB,CAAC;AACpD,CAAC,CAAC;AAjIW,QAAA,sBAAsB,0BAiIjC;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;;;;wBAIJ,IAAI;;;;;;;;mDAQuB,CAAC;AACpD,CAAC,CAAC;AApGW,QAAA,wBAAwB,4BAoGnC;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;;;;wBAIJ,IAAI;;;;;;;;mDAQuB,CAAC;AACpD,CAAC,CAAC;AAtEW,QAAA,mBAAmB,uBAsE9B","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 source: \"/ingest/flags\",\n destination: \"${host}/flags\",\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 source: \"/ingest/flags\",\n destination: \"${host}/flags\",\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 source: \"/ingest/flags\",\n destination: \"${host}/flags\",\n },\n ];\n },\n // This is required to support PostHog trailing slash API requests\n skipTrailingSlashRedirect: true,\n}\nmodule.exports = nextConfig\n--------------------------------------------------`;\n};\n"]}
|