@posthog/wizard 0.4.1 → 0.6.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.
Files changed (53) hide show
  1. package/README.md +21 -15
  2. package/dist/src/lib/config.d.ts +29 -1
  3. package/dist/src/lib/config.js +36 -0
  4. package/dist/src/lib/config.js.map +1 -1
  5. package/dist/src/lib/constants.d.ts +3 -1
  6. package/dist/src/lib/constants.js +6 -0
  7. package/dist/src/lib/constants.js.map +1 -1
  8. package/dist/src/lib/messages.d.ts +10 -0
  9. package/dist/src/lib/messages.js +37 -0
  10. package/dist/src/lib/messages.js.map +1 -0
  11. package/dist/src/lib/prompts.js +4 -1
  12. package/dist/src/lib/prompts.js.map +1 -1
  13. package/dist/src/nextjs/docs.js +4 -2
  14. package/dist/src/nextjs/docs.js.map +1 -1
  15. package/dist/src/nextjs/nextjs-wizard.js +18 -8
  16. package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
  17. package/dist/src/react/docs.d.ts +1 -2
  18. package/dist/src/react/docs.js +9 -3
  19. package/dist/src/react/docs.js.map +1 -1
  20. package/dist/src/react/react-wizard.js +17 -8
  21. package/dist/src/react/react-wizard.js.map +1 -1
  22. package/dist/src/react-native/docs.d.ts +5 -0
  23. package/dist/src/react-native/docs.js +31 -0
  24. package/dist/src/react-native/docs.js.map +1 -0
  25. package/dist/src/react-native/react-native-wizard.d.ts +2 -0
  26. package/dist/src/react-native/react-native-wizard.js +123 -0
  27. package/dist/src/react-native/react-native-wizard.js.map +1 -0
  28. package/dist/src/run.d.ts +1 -0
  29. package/dist/src/run.js +11 -0
  30. package/dist/src/run.js.map +1 -1
  31. package/dist/src/svelte/docs.d.ts +3 -0
  32. package/dist/src/svelte/docs.js +110 -0
  33. package/dist/src/svelte/docs.js.map +1 -0
  34. package/dist/src/svelte/svelte-wizard.d.ts +2 -0
  35. package/dist/src/svelte/svelte-wizard.js +113 -0
  36. package/dist/src/svelte/svelte-wizard.js.map +1 -0
  37. package/dist/src/utils/clack-utils.js +10 -5
  38. package/dist/src/utils/clack-utils.js.map +1 -1
  39. package/dist/src/utils/package-manager.d.ts +1 -0
  40. package/dist/src/utils/package-manager.js +23 -2
  41. package/dist/src/utils/package-manager.js.map +1 -1
  42. package/dist/src/utils/rules/add-editor-rules.d.ts +9 -0
  43. package/dist/src/utils/rules/add-editor-rules.js +90 -0
  44. package/dist/src/utils/rules/add-editor-rules.js.map +1 -0
  45. package/dist/src/utils/rules/add-editor-rules.ts +86 -0
  46. package/dist/src/utils/rules/next-rules.md +9 -0
  47. package/dist/src/utils/rules/react-native-rules.md +7 -0
  48. package/dist/src/utils/rules/react-rules.md +7 -0
  49. package/dist/src/utils/rules/svelte-rules.md +7 -0
  50. package/dist/src/utils/rules/universal.md +20 -0
  51. package/dist/src/utils/types.d.ts +4 -0
  52. package/dist/src/utils/types.js.map +1 -1
  53. package/package.json +2 -2
package/README.md CHANGED
@@ -2,8 +2,9 @@
2
2
  <img alt="posthoglogo" src="https://user-images.githubusercontent.com/65415371/205059737-c8a4f836-4889-4654-902e-f302b187b6a0.png">
3
3
  </p>
4
4
 
5
- > **⚠️ Experimental:** This wizard is still in an experimental phase.
6
- > If you have any feedback, please drop an email to **joshua** [at] **posthog** [dot] **com**.
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]
7
+ > **com**.
7
8
 
8
9
  <h1>PostHog Wizard ✨</h1>
9
10
  <h4>The PostHog Wizard helps you quickly add PostHog to your project using AI.</h4>
@@ -16,21 +17,26 @@ To use the wizard, you can run it directly using:
16
17
  npx @posthog/wizard
17
18
  ```
18
19
 
19
- Currently the wizard can be used for React & Next.js projects. If you have other integrations you would like the wizard to support, please open a [GitHub issue](https://github.com/posthog/wizard/issues)!
20
+ Currently the wizard can be used for React, NextJS, Svelte and React Native
21
+ projects. If you have other integrations you would like the wizard to support,
22
+ please open a [GitHub issue](https://github.com/posthog/wizard/issues)!
20
23
 
21
24
  # Options
22
25
 
23
26
  The following CLI arguments are available:
24
27
 
25
- | Option | Description | Type | Default | Choices | Environment Variable |
26
- | ----------------- | -------------------------------------------------------------------------- | ------- | ------------------------------- | ----------------- | ---------------------------- |
27
- | `--help` | Show help | boolean | | | |
28
- | `--version` | Show version number | boolean | | | |
29
- | `--debug` | Enable verbose logging | boolean | `false` | | `POSTHOG_WIZARD_DEBUG` |
30
- | `--integration` | Choose the integration to setup | choices | Select integration during setup | "nextjs", "react" | `POSTHOG_WIZARD_INTEGRATION` |
31
- | `--force-install` | Force install the SDK NPM package (use with caution!) | boolean | `false` | | |
32
- | `--install-dir` | Relative path to install in | string | `.` | | `POSTHOG_WIZARD_INSTALL_DIR` |
33
- | `--region` | PostHog region to use | choices | | "us", "eu" | `POSTHOG_WIZARD_REGION` |
34
- | `--default` | Select the default option for all questions automatically (where possible) | boolean | `false` | | `POSTHOG_WIZARD_DEFAULT` |
35
-
36
- > Note: A large amount of the scaffolding for this came from the amazing Sentry wizard, which you can find [here](https://github.com/getsentry/sentry-wizard) 💖
28
+ | Option | Description | Type | Default | Choices | Environment Variable |
29
+ | ----------------- | -------------------------------------------------------------------------- | ------- | ------------------------------- | ------------------------------------------- | ---------------------------- |
30
+ | `--help` | Show help | boolean | | | |
31
+ | `--version` | Show version number | boolean | | | |
32
+ | `--debug` | Enable verbose logging | boolean | `false` | | `POSTHOG_WIZARD_DEBUG` |
33
+ | `--integration` | Choose the integration to setup | choices | Select integration during setup | "nextjs", "react", "svelte", "react-native" | `POSTHOG_WIZARD_INTEGRATION` |
34
+ | `--force-install` | Force install the SDK NPM package (use with caution!) | boolean | `false` | | |
35
+ | `--install-dir` | Relative path to install in | string | `.` | | `POSTHOG_WIZARD_INSTALL_DIR` |
36
+ | `--region` | PostHog region to use | choices | | "us", "eu" | `POSTHOG_WIZARD_REGION` |
37
+ | `--default` | Select the default option for all questions automatically (where possible) | boolean | `false` | | `POSTHOG_WIZARD_DEFAULT` |
38
+ | `--signup` | Create a new PostHog account during setup | boolean | `false` | | `POSTHOG_WIZARD_SIGNUP` |
39
+
40
+ > Note: A large amount of the scaffolding for this came from the amazing Sentry
41
+ > wizard, which you can find [here](https://github.com/getsentry/sentry-wizard)
42
+ > 💖
@@ -8,6 +8,9 @@ export declare const INTEGRATION_CONFIG: {
8
8
  readonly detect: (options: Pick<WizardOptions, "installDir">) => Promise<boolean>;
9
9
  readonly generateFilesRules: "";
10
10
  readonly filterFilesRules: "";
11
+ readonly docsUrl: "https://posthog.com/docs/libraries/next-js";
12
+ readonly changes: "• Installed posthog-js & posthog-node packages\n• Initialized PostHog, and added pageview tracking\n• Created a PostHogClient to use PostHog server-side\n• Setup a reverse proxy to avoid ad blockers blocking analytics requests\n• Added your Project API key to your .env/.env.local file";
13
+ readonly nextSteps: "• Call posthog.identify() when a user signs into your app\n• Call posthog.capture() to capture custom events in your app\n• Upload environment variables to your production environment";
11
14
  };
12
15
  readonly react: {
13
16
  readonly name: "React";
@@ -16,6 +19,31 @@ export declare const INTEGRATION_CONFIG: {
16
19
  readonly detect: (options: Pick<WizardOptions, "installDir">) => Promise<boolean>;
17
20
  readonly generateFilesRules: "";
18
21
  readonly filterFilesRules: "";
22
+ readonly docsUrl: "https://posthog.com/docs/libraries/react";
23
+ readonly changes: "• Installed posthog-js package\n• Added PostHogProvider to the root of the app, to initialize PostHog and enable autocapture\n• Added your Project API key to your .env/.env.local file";
24
+ readonly nextSteps: "• Call posthog.identify() when a user signs into your app\n• Call posthog.capture() to capture custom events in your app\n• Upload environment variables to your production environment";
25
+ };
26
+ readonly svelte: {
27
+ readonly name: "Svelte";
28
+ readonly filterPatterns: ["**/*.{svelte,ts,js,jsx,tsx}"];
29
+ readonly ignorePatterns: ["node_modules", "dist", "build", "public", "static"];
30
+ readonly detect: (options: Pick<WizardOptions, "installDir">) => Promise<boolean>;
31
+ readonly generateFilesRules: "";
32
+ readonly filterFilesRules: "";
33
+ readonly docsUrl: "https://posthog.com/docs/libraries/svelte";
34
+ readonly changes: "• Installed posthog-js & posthog-node packages\n• Added PostHog initialization to your Svelte app\n• Setup pageview & pageleave tracking\n• Setup event auto - capture to capture events as users interact with your app\n• Added a getPostHogClient() function to use PostHog server-side\n• Added your Project API key to your .env/.env.local file";
35
+ readonly nextSteps: "• Call posthog.identify() when a user signs into your app\n• Use getPostHogClient() to start capturing events server - side\n• Upload environment variables to your production environment";
36
+ };
37
+ readonly "react-native": {
38
+ readonly name: "React Native";
39
+ readonly filterPatterns: ["**/*.{ts,js,jsx,tsx}"];
40
+ readonly ignorePatterns: ["node_modules", "dist", "build", "public", "static"];
41
+ readonly detect: (options: Pick<WizardOptions, "installDir">) => Promise<boolean>;
42
+ readonly generateFilesRules: "";
43
+ readonly filterFilesRules: "";
44
+ readonly docsUrl: "https://posthog.com/docs/libraries/react-native";
45
+ readonly changes: "• Installed required packages\n• Added PostHogProvider to the root of the app\n• Enabled autocapture and session replay";
46
+ readonly nextSteps: "• Call posthog.identify() when a user signs into your app\n• Call posthog.capture() to capture custom events in your app";
19
47
  };
20
48
  };
21
- export declare const INTEGRATION_ORDER: readonly [Integration.nextjs, Integration.react];
49
+ export declare const INTEGRATION_ORDER: readonly [Integration.nextjs, Integration.svelte, Integration.reactNative, Integration.react];
@@ -22,6 +22,9 @@ exports.INTEGRATION_CONFIG = {
22
22
  },
23
23
  generateFilesRules: '',
24
24
  filterFilesRules: '',
25
+ docsUrl: 'https://posthog.com/docs/libraries/next-js',
26
+ changes: '• Installed posthog-js & posthog-node packages\n• Initialized PostHog, and added pageview tracking\n• Created a PostHogClient to use PostHog server-side\n• Setup a reverse proxy to avoid ad blockers blocking analytics requests\n• Added your Project API key to your .env/.env.local file',
27
+ nextSteps: '• Call posthog.identify() when a user signs into your app\n• Call posthog.capture() to capture custom events in your app\n• Upload environment variables to your production environment',
25
28
  },
26
29
  [constants_1.Integration.react]: {
27
30
  name: 'React',
@@ -40,10 +43,43 @@ exports.INTEGRATION_CONFIG = {
40
43
  },
41
44
  generateFilesRules: '',
42
45
  filterFilesRules: '',
46
+ docsUrl: 'https://posthog.com/docs/libraries/react',
47
+ changes: '• Installed posthog-js package\n• Added PostHogProvider to the root of the app, to initialize PostHog and enable autocapture\n• Added your Project API key to your .env/.env.local file',
48
+ nextSteps: '• Call posthog.identify() when a user signs into your app\n• Call posthog.capture() to capture custom events in your app\n• Upload environment variables to your production environment',
49
+ },
50
+ [constants_1.Integration.svelte]: {
51
+ name: 'Svelte',
52
+ filterPatterns: ['**/*.{svelte,ts,js,jsx,tsx}'],
53
+ ignorePatterns: ['node_modules', 'dist', 'build', 'public', 'static'],
54
+ detect: async (options) => {
55
+ const packageJson = await (0, clack_utils_1.getPackageDotJson)(options);
56
+ return (0, package_json_1.hasPackageInstalled)('@sveltejs/kit', packageJson);
57
+ },
58
+ generateFilesRules: '',
59
+ filterFilesRules: '',
60
+ docsUrl: 'https://posthog.com/docs/libraries/svelte',
61
+ changes: '• Installed posthog-js & posthog-node packages\n• Added PostHog initialization to your Svelte app\n• Setup pageview & pageleave tracking\n• Setup event auto - capture to capture events as users interact with your app\n• Added a getPostHogClient() function to use PostHog server-side\n• Added your Project API key to your .env/.env.local file',
62
+ nextSteps: '• Call posthog.identify() when a user signs into your app\n• Use getPostHogClient() to start capturing events server - side\n• Upload environment variables to your production environment',
63
+ },
64
+ [constants_1.Integration.reactNative]: {
65
+ name: 'React Native',
66
+ filterPatterns: ['**/*.{ts,js,jsx,tsx}'],
67
+ ignorePatterns: ['node_modules', 'dist', 'build', 'public', 'static'],
68
+ detect: async (options) => {
69
+ const packageJson = await (0, clack_utils_1.getPackageDotJson)(options);
70
+ return (0, package_json_1.hasPackageInstalled)('react-native', packageJson);
71
+ },
72
+ generateFilesRules: '',
73
+ filterFilesRules: '',
74
+ docsUrl: 'https://posthog.com/docs/libraries/react-native',
75
+ changes: '• Installed required packages\n• Added PostHogProvider to the root of the app\n• Enabled autocapture and session replay',
76
+ nextSteps: '• Call posthog.identify() when a user signs into your app\n• Call posthog.capture() to capture custom events in your app',
43
77
  },
44
78
  };
45
79
  exports.INTEGRATION_ORDER = [
46
80
  constants_1.Integration.nextjs,
81
+ constants_1.Integration.svelte,
82
+ constants_1.Integration.reactNative,
47
83
  constants_1.Integration.react,
48
84
  ];
49
85
  //# sourceMappingURL=config.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/lib/config.ts"],"names":[],"mappings":";;;AAAA,sDAAyD;AACzD,wDAA4D;AAE5D,2CAA0C;AAW7B,QAAA,kBAAkB,GAAG;IAChC,CAAC,uBAAW,CAAC,MAAM,CAAC,EAAE;QACpB,IAAI,EAAE,SAAS;QACf,cAAc,EAAE,CAAC,8BAA8B,CAAC;QAChD,cAAc,EAAE;YACd,cAAc;YACd,MAAM;YACN,OAAO;YACP,QAAQ;YACR,QAAQ;YACR,cAAc;SACf;QACD,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;YACxB,MAAM,WAAW,GAAG,MAAM,IAAA,+BAAiB,EAAC,OAAO,CAAC,CAAC;YACrD,OAAO,IAAA,kCAAmB,EAAC,MAAM,EAAE,WAAW,CAAC,CAAC;QAClD,CAAC;QACD,kBAAkB,EAAE,EAAE;QACtB,gBAAgB,EAAE,EAAE;KACrB;IACD,CAAC,uBAAW,CAAC,KAAK,CAAC,EAAE;QACnB,IAAI,EAAE,OAAO;QACb,cAAc,EAAE,CAAC,sBAAsB,CAAC;QACxC,cAAc,EAAE;YACd,cAAc;YACd,MAAM;YACN,OAAO;YACP,QAAQ;YACR,QAAQ;YACR,QAAQ;SACT;QACD,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;YACxB,MAAM,WAAW,GAAG,MAAM,IAAA,+BAAiB,EAAC,OAAO,CAAC,CAAC;YACrD,OAAO,IAAA,kCAAmB,EAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QACnD,CAAC;QACD,kBAAkB,EAAE,EAAE;QACtB,gBAAgB,EAAE,EAAE;KACrB;CACwD,CAAC;AAE/C,QAAA,iBAAiB,GAAG;IAC/B,uBAAW,CAAC,MAAM;IAClB,uBAAW,CAAC,KAAK;CACT,CAAC","sourcesContent":["import { getPackageDotJson } from '../utils/clack-utils';\nimport { hasPackageInstalled } from '../utils/package-json';\nimport type { WizardOptions } from '../utils/types';\nimport { Integration } from './constants';\n\ntype IntegrationConfig = {\n name: string;\n filterPatterns: string[];\n ignorePatterns: string[];\n detect: (options: Pick<WizardOptions, 'installDir'>) => Promise<boolean>;\n generateFilesRules: string;\n filterFilesRules: string;\n};\n\nexport const INTEGRATION_CONFIG = {\n [Integration.nextjs]: {\n name: 'Next.js',\n filterPatterns: ['**/*.{tsx,ts,jsx,js,mjs,cjs}'],\n ignorePatterns: [\n 'node_modules',\n 'dist',\n 'build',\n 'public',\n 'static',\n 'next-env.d.*',\n ],\n detect: async (options) => {\n const packageJson = await getPackageDotJson(options);\n return hasPackageInstalled('next', packageJson);\n },\n generateFilesRules: '',\n filterFilesRules: '',\n },\n [Integration.react]: {\n name: 'React',\n filterPatterns: ['**/*.{tsx,ts,jsx,js}'],\n ignorePatterns: [\n 'node_modules',\n 'dist',\n 'build',\n 'public',\n 'static',\n 'assets',\n ],\n detect: async (options) => {\n const packageJson = await getPackageDotJson(options);\n return hasPackageInstalled('react', packageJson);\n },\n generateFilesRules: '',\n filterFilesRules: '',\n },\n} as const satisfies Record<Integration, IntegrationConfig>;\n\nexport const INTEGRATION_ORDER = [\n Integration.nextjs,\n Integration.react,\n] as const;\n"]}
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/lib/config.ts"],"names":[],"mappings":";;;AAAA,sDAAyD;AACzD,wDAA4D;AAE5D,2CAA0C;AAc7B,QAAA,kBAAkB,GAAG;IAChC,CAAC,uBAAW,CAAC,MAAM,CAAC,EAAE;QACpB,IAAI,EAAE,SAAS;QACf,cAAc,EAAE,CAAC,8BAA8B,CAAC;QAChD,cAAc,EAAE;YACd,cAAc;YACd,MAAM;YACN,OAAO;YACP,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AAE,WAAW,CAAC,CAAC;QAC3D,CAAC;QACD,kBAAkB,EAAE,EAAE;QACtB,gBAAgB,EAAE,EAAE;QACpB,OAAO,EAAE,2CAA2C;QACpD,OAAO,EACL,uVAAuV;QACzV,SAAS,EACP,4LAA4L;KAC/L;IACD,CAAC,uBAAW,CAAC,WAAW,CAAC,EAAE;QACzB,IAAI,EAAE,cAAc;QACpB,cAAc,EAAE,CAAC,sBAAsB,CAAC;QACxC,cAAc,EAAE,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC;QACrE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;YACxB,MAAM,WAAW,GAAG,MAAM,IAAA,+BAAiB,EAAC,OAAO,CAAC,CAAC;YACrD,OAAO,IAAA,kCAAmB,EAAC,cAAc,EAAE,WAAW,CAAC,CAAC;QAC1D,CAAC;QACD,kBAAkB,EAAE,EAAE;QACtB,gBAAgB,EAAE,EAAE;QACpB,OAAO,EAAE,iDAAiD;QAC1D,OAAO,EACL,yHAAyH;QAC3H,SAAS,EACP,0HAA0H;KAC7H;CACwD,CAAC;AAE/C,QAAA,iBAAiB,GAAG;IAC/B,uBAAW,CAAC,MAAM;IAClB,uBAAW,CAAC,MAAM;IAClB,uBAAW,CAAC,WAAW;IACvB,uBAAW,CAAC,KAAK;CACT,CAAC","sourcesContent":["import { getPackageDotJson } from '../utils/clack-utils';\nimport { hasPackageInstalled } from '../utils/package-json';\nimport type { WizardOptions } from '../utils/types';\nimport { Integration } from './constants';\n\ntype IntegrationConfig = {\n name: string;\n filterPatterns: string[];\n ignorePatterns: string[];\n detect: (options: Pick<WizardOptions, 'installDir'>) => Promise<boolean>;\n generateFilesRules: string;\n filterFilesRules: string;\n docsUrl: string;\n changes: string;\n nextSteps: string;\n};\n\nexport const INTEGRATION_CONFIG = {\n [Integration.nextjs]: {\n name: 'Next.js',\n filterPatterns: ['**/*.{tsx,ts,jsx,js,mjs,cjs}'],\n ignorePatterns: [\n 'node_modules',\n 'dist',\n 'build',\n 'public',\n 'static',\n 'next-env.d.*',\n ],\n detect: async (options) => {\n const packageJson = await getPackageDotJson(options);\n return hasPackageInstalled('next', packageJson);\n },\n generateFilesRules: '',\n filterFilesRules: '',\n docsUrl: 'https://posthog.com/docs/libraries/next-js',\n changes:\n '• Installed posthog-js & posthog-node packages\\n• Initialized PostHog, and added pageview tracking\\n• Created a PostHogClient to use PostHog server-side\\n• Setup a reverse proxy to avoid ad blockers blocking analytics requests\\n• Added your Project API key to your .env/.env.local file',\n nextSteps:\n '• Call posthog.identify() when a user signs into your app\\n• Call posthog.capture() to capture custom events in your app\\n• Upload environment variables to your production environment',\n },\n [Integration.react]: {\n name: 'React',\n filterPatterns: ['**/*.{tsx,ts,jsx,js}'],\n ignorePatterns: [\n 'node_modules',\n 'dist',\n 'build',\n 'public',\n 'static',\n 'assets',\n ],\n detect: async (options) => {\n const packageJson = await getPackageDotJson(options);\n return hasPackageInstalled('react', packageJson);\n },\n generateFilesRules: '',\n filterFilesRules: '',\n docsUrl: 'https://posthog.com/docs/libraries/react',\n changes:\n '• Installed posthog-js package\\n• Added PostHogProvider to the root of the app, to initialize PostHog and enable autocapture\\n• Added your Project API key to your .env/.env.local file',\n nextSteps:\n '• Call posthog.identify() when a user signs into your app\\n• Call posthog.capture() to capture custom events in your app\\n• Upload environment variables to your production environment',\n },\n [Integration.svelte]: {\n name: 'Svelte',\n filterPatterns: ['**/*.{svelte,ts,js,jsx,tsx}'],\n ignorePatterns: ['node_modules', 'dist', 'build', 'public', 'static'],\n detect: async (options) => {\n const packageJson = await getPackageDotJson(options);\n return hasPackageInstalled('@sveltejs/kit', packageJson);\n },\n generateFilesRules: '',\n filterFilesRules: '',\n docsUrl: 'https://posthog.com/docs/libraries/svelte',\n changes:\n '• Installed posthog-js & posthog-node packages\\n• Added PostHog initialization to your Svelte app\\n• Setup pageview & pageleave tracking\\n• Setup event auto - capture to capture events as users interact with your app\\n• Added a getPostHogClient() function to use PostHog server-side\\n• Added your Project API key to your .env/.env.local file',\n nextSteps:\n '• Call posthog.identify() when a user signs into your app\\n• Use getPostHogClient() to start capturing events server - side\\n• Upload environment variables to your production environment',\n },\n [Integration.reactNative]: {\n name: 'React Native',\n filterPatterns: ['**/*.{ts,js,jsx,tsx}'],\n ignorePatterns: ['node_modules', 'dist', 'build', 'public', 'static'],\n detect: async (options) => {\n const packageJson = await getPackageDotJson(options);\n return hasPackageInstalled('react-native', packageJson);\n },\n generateFilesRules: '',\n filterFilesRules: '',\n docsUrl: 'https://posthog.com/docs/libraries/react-native',\n changes:\n '• Installed required packages\\n• Added PostHogProvider to the root of the app\\n• Enabled autocapture and session replay',\n nextSteps:\n '• Call posthog.identify() when a user signs into your app\\n• Call posthog.capture() to capture custom events in your app',\n },\n} as const satisfies Record<Integration, IntegrationConfig>;\n\nexport const INTEGRATION_ORDER = [\n Integration.nextjs,\n Integration.svelte,\n Integration.reactNative,\n Integration.react,\n] as const;\n"]}
@@ -1,6 +1,8 @@
1
1
  export declare enum Integration {
2
2
  nextjs = "nextjs",
3
- react = "react"
3
+ react = "react",
4
+ svelte = "svelte",
5
+ reactNative = "react-native"
4
6
  }
5
7
  export declare function getIntegrationDescription(type: string): string;
6
8
  type IntegrationChoice = {
@@ -7,6 +7,8 @@ var Integration;
7
7
  (function (Integration) {
8
8
  Integration["nextjs"] = "nextjs";
9
9
  Integration["react"] = "react";
10
+ Integration["svelte"] = "svelte";
11
+ Integration["reactNative"] = "react-native";
10
12
  })(Integration || (exports.Integration = Integration = {}));
11
13
  function getIntegrationDescription(type) {
12
14
  switch (type) {
@@ -14,6 +16,10 @@ function getIntegrationDescription(type) {
14
16
  return 'Next.js';
15
17
  case Integration.react:
16
18
  return 'React';
19
+ case Integration.reactNative:
20
+ return 'React Native';
21
+ case Integration.svelte:
22
+ return 'Svelte';
17
23
  default:
18
24
  throw new Error(`Unknown integration ${type}`);
19
25
  }
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/lib/constants.ts"],"names":[],"mappings":";;;AAKA,8DASC;AAOD,sDAKC;AA1BD,IAAY,WAGX;AAHD,WAAY,WAAW;IACrB,gCAAiB,CAAA;IACjB,8BAAe,CAAA;AACjB,CAAC,EAHW,WAAW,2BAAX,WAAW,QAGtB;AAED,SAAgB,yBAAyB,CAAC,IAAY;IACpD,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,WAAW,CAAC,MAAM;YACrB,OAAO,SAAS,CAAC;QACnB,KAAK,WAAW,CAAC,KAAK;YACpB,OAAO,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,KAAK,CAAC;AAEf,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,cAAM;IACtC,CAAC,CAAC,uBAAuB;IACzB,CAAC,CAAC,gCAAgC,CAAC;AACxB,QAAA,qBAAqB,GAAG,gCAAgC,CAAC","sourcesContent":["export enum Integration {\n nextjs = 'nextjs',\n react = 'react',\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 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 = 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 = IS_DEV\n ? 'http://localhost:8010'\n : 'https://internal-t.posthog.com';\nexport const DUMMY_PROJECT_API_KEY = '_YOUR_POSTHOG_PROJECT_API_KEY_';\n"]}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/lib/constants.ts"],"names":[],"mappings":";;;AAOA,8DAaC;AAOD,sDAKC;AAhCD,IAAY,WAKX;AALD,WAAY,WAAW;IACrB,gCAAiB,CAAA;IACjB,8BAAe,CAAA;IACf,gCAAiB,CAAA;IACjB,2CAA4B,CAAA;AAC9B,CAAC,EALW,WAAW,2BAAX,WAAW,QAKtB;AAED,SAAgB,yBAAyB,CAAC,IAAY;IACpD,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,WAAW,CAAC,MAAM;YACrB,OAAO,SAAS,CAAC;QACnB,KAAK,WAAW,CAAC,KAAK;YACpB,OAAO,OAAO,CAAC;QACjB,KAAK,WAAW,CAAC,WAAW;YAC1B,OAAO,cAAc,CAAC;QACxB,KAAK,WAAW,CAAC,MAAM;YACrB,OAAO,QAAQ,CAAC;QAClB;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,KAAK,CAAC;AAEf,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,cAAM;IACtC,CAAC,CAAC,uBAAuB;IACzB,CAAC,CAAC,gCAAgC,CAAC;AACxB,QAAA,qBAAqB,GAAG,gCAAgC,CAAC","sourcesContent":["export enum Integration {\n nextjs = 'nextjs',\n react = 'react',\n svelte = 'svelte',\n reactNative = 'react-native',\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 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 = 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 = IS_DEV\n ? 'http://localhost:8010'\n : 'https://internal-t.posthog.com';\nexport const DUMMY_PROJECT_API_KEY = '_YOUR_POSTHOG_PROJECT_API_KEY_';\n"]}
@@ -0,0 +1,10 @@
1
+ import type { CloudRegion, WizardOptions } from '../utils/types';
2
+ import type { PackageManager } from '../utils/package-manager';
3
+ import { Integration } from './constants';
4
+ export declare const getOutroMessage: ({ options, integration, cloudRegion, addedEditorRules, packageManager, }: {
5
+ options: WizardOptions;
6
+ integration: Integration;
7
+ cloudRegion: CloudRegion;
8
+ addedEditorRules: boolean;
9
+ packageManager?: PackageManager;
10
+ }) => string;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getOutroMessage = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const urls_1 = require("../utils/urls");
9
+ const constants_1 = require("./constants");
10
+ const config_1 = require("./config");
11
+ const getOutroMessage = ({ options, integration, cloudRegion, addedEditorRules, packageManager, }) => {
12
+ const continueUrl = options.signup
13
+ ? `${(0, urls_1.getCloudUrlFromRegion)(cloudRegion)}/products?source=wizard`
14
+ : undefined;
15
+ const integrationConfig = config_1.INTEGRATION_CONFIG[integration];
16
+ return `
17
+ ${chalk_1.default.green('Successfully installed PostHog!')}
18
+
19
+ ${chalk_1.default.cyan('Changes made:')}
20
+ ${integrationConfig.changes}
21
+ ${addedEditorRules ? `• Added Cursor rules for PostHog` : ''}
22
+
23
+ ${chalk_1.default.yellow('Next steps:')}
24
+ ${integrationConfig.nextSteps}
25
+
26
+ Learn more about PostHog + ${integrationConfig.name}: ${chalk_1.default.cyan(integrationConfig.docsUrl)}
27
+ ${continueUrl ? `\nContinue onboarding: ${chalk_1.default.cyan(continueUrl)}\n` : ``}
28
+ Note: This uses experimental AI to setup your project. It might have got it wrong, please check!
29
+
30
+ You should validate your setup by (re)starting your dev environment${packageManager
31
+ ? ` (e.g. ${chalk_1.default.cyan(`${packageManager.runScriptCommand} dev`)}).`
32
+ : `.`}
33
+
34
+ ${chalk_1.default.dim(`If you encounter any issues, let us know here: ${constants_1.ISSUES_URL}`)}`;
35
+ };
36
+ exports.getOutroMessage = getOutroMessage;
37
+ //# sourceMappingURL=messages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.js","sourceRoot":"","sources":["../../../src/lib/messages.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAE1B,wCAAsD;AAEtD,2CAAsD;AACtD,qCAA8C;AAEvC,MAAM,eAAe,GAAG,CAAC,EAC9B,OAAO,EACP,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,cAAc,GAOf,EAAE,EAAE;IACH,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM;QAChC,CAAC,CAAC,GAAG,IAAA,4BAAqB,EAAC,WAAW,CAAC,yBAAyB;QAChE,CAAC,CAAC,SAAS,CAAC;IAEd,MAAM,iBAAiB,GAAG,2BAAkB,CAAC,WAAW,CAAC,CAAC;IAE1D,OAAO;EACP,eAAK,CAAC,KAAK,CAAC,iCAAiC,CAAC;;EAE9C,eAAK,CAAC,IAAI,CAAC,eAAe,CAAC;EAC3B,iBAAiB,CAAC,OAAO;EACzB,gBAAgB,CAAC,CAAC,CAAC,kCAAkC,CAAC,CAAC,CAAC,EAAE;;EAE1D,eAAK,CAAC,MAAM,CAAC,aAAa,CAAC;EAC3B,iBAAiB,CAAC,SAAS;;6BAEA,iBAAiB,CAAC,IAAI,KAAK,eAAK,CAAC,IAAI,CAC9D,iBAAiB,CAAC,OAAO,CAC1B;EACD,WAAW,CAAC,CAAC,CAAC,0BAA0B,eAAK,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;;;qEAItE,cAAc;QACZ,CAAC,CAAC,UAAU,eAAK,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC,gBAAgB,MAAM,CAAC,IAAI;QACpE,CAAC,CAAC,GACN;;EAEA,eAAK,CAAC,GAAG,CAAC,kDAAkD,sBAAU,EAAE,CAAC,EAAE,CAAC;AAC9E,CAAC,CAAC;AA1CW,QAAA,eAAe,mBA0C1B","sourcesContent":["import chalk from 'chalk';\nimport type { CloudRegion, WizardOptions } from '../utils/types';\nimport { getCloudUrlFromRegion } from '../utils/urls';\nimport type { PackageManager } from '../utils/package-manager';\nimport { ISSUES_URL, Integration } from './constants';\nimport { INTEGRATION_CONFIG } from './config';\n\nexport const getOutroMessage = ({\n options,\n integration,\n cloudRegion,\n addedEditorRules,\n packageManager,\n}: {\n options: WizardOptions;\n integration: Integration;\n cloudRegion: CloudRegion;\n addedEditorRules: boolean;\n packageManager?: PackageManager;\n}) => {\n const continueUrl = options.signup\n ? `${getCloudUrlFromRegion(cloudRegion)}/products?source=wizard`\n : undefined;\n\n const integrationConfig = INTEGRATION_CONFIG[integration];\n\n return `\n${chalk.green('Successfully installed PostHog!')} \n \n${chalk.cyan('Changes made:')}\n${integrationConfig.changes}\n${addedEditorRules ? `• Added Cursor rules for PostHog` : ''}\n \n${chalk.yellow('Next steps:')}\n${integrationConfig.nextSteps}\n\nLearn more about PostHog + ${integrationConfig.name}: ${chalk.cyan(\n integrationConfig.docsUrl,\n )}\n${continueUrl ? `\\nContinue onboarding: ${chalk.cyan(continueUrl)}\\n` : ``}\nNote: This uses experimental AI to setup your project. It might have got it wrong, please check!\n\nYou should validate your setup by (re)starting your dev environment${\n packageManager\n ? ` (e.g. ${chalk.cyan(`${packageManager.runScriptCommand} dev`)}).`\n : `.`\n }\n\n${chalk.dim(`If you encounter any issues, let us know here: ${ISSUES_URL}`)}`;\n};\n"]}
@@ -22,10 +22,12 @@ Rules:
22
22
  - Only return files that you think will be required to look at or modify to integrate PostHog.
23
23
  - Do not return files that are unlikely to require modification based on the documentation.
24
24
  - If you are unsure, return the file, since it's better to have more files than less.
25
+ - If two files might include the content you need to edit, return both.
25
26
  - If you create a new file, it should not conflict with any existing files.
26
27
  - If the user is using TypeScript, you should return .ts and .tsx files.
27
- - The file structure of the project may be different than the documentation, you should follow the file structure of the project.
28
+ - The file structure of the project may be different than the documentation, you should follow the file structure of the project. e.g. if there is an existing file containing providers, you should edit that file instead of creating a new one.
28
29
  {integration_rules}
30
+ - Look for existing files that contain providers, components, hooks, etc. and edit those files instead of creating new ones if appropriate.
29
31
 
30
32
  Installation documentation:
31
33
  {documentation}
@@ -56,6 +58,7 @@ Rules:
56
58
  - If the current file is empty, and you think it should be created, you can add the contents of the new file.
57
59
  - The file structure of the project may be different than the documentation, you should follow the file structure of the project.
58
60
  - Use relative imports if you are unsure what the project import paths are.
61
+ - It's okay not to edit a file if it's not needed (e.g. if you have already edited another one or this one is not needed).
59
62
  {integration_rules}
60
63
 
61
64
 
@@ -1 +1 @@
1
- {"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../../src/lib/prompts.ts"],"names":[],"mappings":";;;AAAA,qDAAyD;AAE5C,QAAA,6BAA6B,GAAG,IAAI,wBAAc,CAAC;IAC9D,cAAc,EAAE;QACd,eAAe;QACf,WAAW;QACX,kBAAkB;QAClB,mBAAmB;KACpB;IACD,QAAQ,EAAE;;;;;;;;;;;;;;;;;;;;;;;YAuBA;CACX,CAAC,CAAC;AAEU,QAAA,qCAAqC,GAAG,IAAI,wBAAc,CAAC;IACtE,cAAc,EAAE;QACd,cAAc;QACd,eAAe;QACf,WAAW;QACX,eAAe;QACf,iBAAiB;QACjB,kBAAkB;QAClB,mBAAmB;KACpB;IACD,QAAQ,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eA+BG;CACd,CAAC,CAAC","sourcesContent":["import { PromptTemplate } from '@langchain/core/prompts';\n\nexport const baseFilterFilesPromptTemplate = new PromptTemplate({\n inputVariables: [\n 'documentation',\n 'file_list',\n 'integration_name',\n 'integration_rules',\n ],\n template: `You are a PostHog installation wizard, a master AI programming assistant that implements PostHog for {integration_name} projects.\nGiven the following list of file paths from a project, determine which files are likely to require modifications \nto integrate PostHog. Use the installation documentation as a reference for what files might need modifications, do not include files that are unlikely to require modification based on the documentation.\n\n- If you would like to create a new file, you can include the file path in your response.\n- If you would like to modify an existing file, you can include the file path in your response.\n\nYou should return all files that you think will be required to look at or modify to integrate PostHog. You should return them in the order you would like to see them processed, with new files first, followed by the files that you want to update to integrate PostHog.\n\nRules:\n- Only return files that you think will be required to look at or modify to integrate PostHog.\n- Do not return files that are unlikely to require modification based on the documentation.\n- If you are unsure, return the file, since it's better to have more files than less.\n- If you create a new file, it should not conflict with any existing files.\n- If the user is using TypeScript, you should return .ts and .tsx files.\n- The file structure of the project may be different than the documentation, you should follow the file structure of the project.\n{integration_rules}\n\nInstallation documentation:\n{documentation}\n\nAll current files in the repository:\n\n{file_list}`,\n});\n\nexport const baseGenerateFileChangesPromptTemplate = new PromptTemplate({\n inputVariables: [\n 'file_content',\n 'documentation',\n 'file_path',\n 'changed_files',\n 'unchanged_files',\n 'integration_name',\n 'integration_rules',\n ],\n template: `You are a PostHog installation wizard, a master AI programming assistant that implements PostHog for {integration_name} projects.\n\nYour task is to update the file to integrate PostHog according to the documentation.\nDo not return a diff — you should return the complete updated file content.\n\nRules:\n- Preserve the existing code formatting and style.\n- Only make the changes required by the documentation.\n- If no changes are needed, return the file as-is.\n- If the current file is empty, and you think it should be created, you can add the contents of the new file.\n- The file structure of the project may be different than the documentation, you should follow the file structure of the project.\n- Use relative imports if you are unsure what the project import paths are.\n{integration_rules}\n\n\nCONTEXT\n---\n\nDocumentation for integrating PostHog with {integration_name}:\n{documentation}\n\nThe file you are updating is:\n{file_path}\n\nHere are the changes you have already made to the project:\n{changed_files}\n\nHere are the files that have not been changed yet:\n{unchanged_files}\n\nBelow is the current file contents:\n{file_content}`,\n});\n"]}
1
+ {"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../../src/lib/prompts.ts"],"names":[],"mappings":";;;AAAA,qDAAyD;AAE5C,QAAA,6BAA6B,GAAG,IAAI,wBAAc,CAAC;IAC9D,cAAc,EAAE;QACd,eAAe;QACf,WAAW;QACX,kBAAkB;QAClB,mBAAmB;KACpB;IACD,QAAQ,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;YAyBA;CACX,CAAC,CAAC;AAEU,QAAA,qCAAqC,GAAG,IAAI,wBAAc,CAAC;IACtE,cAAc,EAAE;QACd,cAAc;QACd,eAAe;QACf,WAAW;QACX,eAAe;QACf,iBAAiB;QACjB,kBAAkB;QAClB,mBAAmB;KACpB;IACD,QAAQ,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eAgCG;CACd,CAAC,CAAC","sourcesContent":["import { PromptTemplate } from '@langchain/core/prompts';\n\nexport const baseFilterFilesPromptTemplate = new PromptTemplate({\n inputVariables: [\n 'documentation',\n 'file_list',\n 'integration_name',\n 'integration_rules',\n ],\n template: `You are a PostHog installation wizard, a master AI programming assistant that implements PostHog for {integration_name} projects.\nGiven the following list of file paths from a project, determine which files are likely to require modifications \nto integrate PostHog. Use the installation documentation as a reference for what files might need modifications, do not include files that are unlikely to require modification based on the documentation.\n\n- If you would like to create a new file, you can include the file path in your response.\n- If you would like to modify an existing file, you can include the file path in your response.\n\nYou should return all files that you think will be required to look at or modify to integrate PostHog. You should return them in the order you would like to see them processed, with new files first, followed by the files that you want to update to integrate PostHog.\n\nRules:\n- Only return files that you think will be required to look at or modify to integrate PostHog.\n- Do not return files that are unlikely to require modification based on the documentation.\n- If you are unsure, return the file, since it's better to have more files than less.\n- If two files might include the content you need to edit, return both.\n- If you create a new file, it should not conflict with any existing files.\n- If the user is using TypeScript, you should return .ts and .tsx files.\n- The file structure of the project may be different than the documentation, you should follow the file structure of the project. e.g. if there is an existing file containing providers, you should edit that file instead of creating a new one.\n{integration_rules}\n- Look for existing files that contain providers, components, hooks, etc. and edit those files instead of creating new ones if appropriate.\n\nInstallation documentation:\n{documentation}\n\nAll current files in the repository:\n\n{file_list}`,\n});\n\nexport const baseGenerateFileChangesPromptTemplate = new PromptTemplate({\n inputVariables: [\n 'file_content',\n 'documentation',\n 'file_path',\n 'changed_files',\n 'unchanged_files',\n 'integration_name',\n 'integration_rules',\n ],\n template: `You are a PostHog installation wizard, a master AI programming assistant that implements PostHog for {integration_name} projects.\n\nYour task is to update the file to integrate PostHog according to the documentation.\nDo not return a diff — you should return the complete updated file content.\n\nRules:\n- Preserve the existing code formatting and style.\n- Only make the changes required by the documentation.\n- If no changes are needed, return the file as-is.\n- If the current file is empty, and you think it should be created, you can add the contents of the new file.\n- The file structure of the project may be different than the documentation, you should follow the file structure of the project.\n- Use relative imports if you are unsure what the project import paths are.\n- It's okay not to edit a file if it's not needed (e.g. if you have already edited another one or this one is not needed).\n{integration_rules}\n\n\nCONTEXT\n---\n\nDocumentation for integrating PostHog with {integration_name}:\n{documentation}\n\nThe file you are updating is:\n{file_path}\n\nHere are the changes you have already made to the project:\n{changed_files}\n\nHere are the files that have not been changed yet:\n{unchanged_files}\n\nBelow is the current file contents:\n{file_content}`,\n});\n"]}
@@ -27,6 +27,7 @@ export function PostHogProvider({ children }: { children: React.ReactNode }) {
27
27
  ui_host: "${(0, urls_1.getUiHostFromHost)(host)}",
28
28
  capture_pageview: false, // We capture pageviews manually
29
29
  capture_pageleave: true, // Enable pageleave capture
30
+ debug: process.env.NODE_ENV === "development",
30
31
  })
31
32
  }, [])
32
33
 
@@ -107,7 +108,7 @@ import { PostHog } from "posthog-node"
107
108
 
108
109
  export default function PostHogClient() {
109
110
  const posthogClient = new PostHog(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
110
- host: "${host}",
111
+ host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
111
112
  flushAt: 1,
112
113
  flushInterval: 0,
113
114
  })
@@ -177,6 +178,7 @@ export default function App({ Component, pageProps }) {
177
178
  loaded: (posthog) => {
178
179
  if (process.env.NODE_ENV === "development") posthog.debug()
179
180
  },
181
+ debug: process.env.NODE_ENV === "development",
180
182
  })
181
183
 
182
184
  const handleRouteChange = () => posthog?.capture("$pageview")
@@ -208,7 +210,7 @@ import { PostHog } from "posthog-node"
208
210
 
209
211
  export default function PostHogClient() {
210
212
  const posthogClient = new PostHog(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
211
- host: "${host}",
213
+ host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
212
214
  flushAt: 1,
213
215
  flushInterval: 0,
214
216
  })
@@ -1 +1 @@
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;;;;;;;;;;;;;;;;;;;kBAmBgB,IAAA,wBAAiB,EAAC,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eA4C1B,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;gBA2BxC,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI;;;;;;;;;;;;aAY1C,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;wBAyBO,IAAA,2BAAoB,EAAC,IAAI,CAAC;;;;wBAI1B,IAAI;;;;wBAIJ,IAAI;;;;;;;;mDAQuB,CAAC;AACpD,CAAC,CAAC;AA3JW,QAAA,sBAAsB,0BA2JjC;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;;;;;;;;;;;;;;;;;;kBAkBgB,IAAA,wBAAiB,EAAC,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;;gBAuBzB,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI;;;;;;;;;;;;aAY1C,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;wBAyBO,IAAA,2BAAoB,EAAC,IAAI,CAAC;;;;wBAI1B,IAAI;;;;wBAIJ,IAAI;;;;;;;;mDAQuB,CAAC;AACpD,CAAC,CAAC;AA3GW,QAAA,wBAAwB,4BA2GnC","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\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 capture_pageview: false, // We capture pageviews manually\n capture_pageleave: true, // Enable pageleave capture\n })\n }, [])\n\n return (\n <PHProvider client={posthog}>\n <SuspendedPostHogPageView />\n {children}\n </PHProvider>\n )\n}\n\n\nfunction PostHogPageView() {\n const pathname = usePathname()\n const searchParams = useSearchParams()\n const posthog = usePostHog()\n\n useEffect(() => {\n if (pathname && posthog) {\n let url = window.origin + pathname\n const search = searchParams.toString()\n if (search) {\n url += \"?\" + search\n }\n posthog.capture(\"$pageview\", { \"$current_url\": url })\n }\n }, [pathname, searchParams, posthog])\n\n return null\n}\n\nfunction SuspendedPostHogPageView() {\n return (\n <Suspense fallback={null}>\n <PostHogPageView />\n </Suspense>\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\nexport default function PostHogClient() {\n const posthogClient = new PostHog(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {\n host: \"${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- Manually capture $pageview events.\n\nExample:\n--------------------------------------------------\nimport { useEffect } from \"react\"\nimport { Router } from \"next/router\"\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 loaded: (posthog) => {\n if (process.env.NODE_ENV === \"development\") posthog.debug()\n },\n })\n\n const handleRouteChange = () => posthog?.capture(\"$pageview\")\n Router.events.on(\"routeChangeComplete\", handleRouteChange)\n\n return () => {\n Router.events.off(\"routeChangeComplete\", handleRouteChange)\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\nexport default function PostHogClient() {\n const posthogClient = new PostHog(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {\n host: \"${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"]}
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;;;;;;;;;;;;;;;;;;;kBAmBgB,IAAA,wBAAiB,EAAC,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eA6C1B,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;gBA2BxC,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAqC/B,IAAA,2BAAoB,EAAC,IAAI,CAAC;;;;wBAI1B,IAAI;;;;wBAIJ,IAAI;;;;;;;;mDAQuB,CAAC;AACpD,CAAC,CAAC;AA5JW,QAAA,sBAAsB,0BA4JjC;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;;;;;;;;;;;;;;;;;;kBAkBgB,IAAA,wBAAiB,EAAC,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;;;gBAwBzB,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAqC/B,IAAA,2BAAoB,EAAC,IAAI,CAAC;;;;wBAI1B,IAAI;;;;wBAIJ,IAAI;;;;;;;;mDAQuB,CAAC;AACpD,CAAC,CAAC;AA5GW,QAAA,wBAAwB,4BA4GnC","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\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 capture_pageview: false, // We capture pageviews manually\n capture_pageleave: true, // Enable pageleave capture\n debug: process.env.NODE_ENV === \"development\",\n })\n }, [])\n\n return (\n <PHProvider client={posthog}>\n <SuspendedPostHogPageView />\n {children}\n </PHProvider>\n )\n}\n\n\nfunction PostHogPageView() {\n const pathname = usePathname()\n const searchParams = useSearchParams()\n const posthog = usePostHog()\n\n useEffect(() => {\n if (pathname && posthog) {\n let url = window.origin + pathname\n const search = searchParams.toString()\n if (search) {\n url += \"?\" + search\n }\n posthog.capture(\"$pageview\", { \"$current_url\": url })\n }\n }, [pathname, searchParams, posthog])\n\n return null\n}\n\nfunction SuspendedPostHogPageView() {\n return (\n <Suspense fallback={null}>\n <PostHogPageView />\n </Suspense>\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\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- Manually capture $pageview events.\n\nExample:\n--------------------------------------------------\nimport { useEffect } from \"react\"\nimport { Router } from \"next/router\"\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 loaded: (posthog) => {\n if (process.env.NODE_ENV === \"development\") posthog.debug()\n },\n debug: process.env.NODE_ENV === \"development\",\n })\n\n const handleRouteChange = () => posthog?.capture(\"$pageview\")\n Router.events.on(\"routeChangeComplete\", handleRouteChange)\n\n return () => {\n Router.events.off(\"routeChangeComplete\", handleRouteChange)\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\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"]}
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
- /* eslint-disable max-lines */
3
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
4
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
4
  };
6
5
  Object.defineProperty(exports, "__esModule", { value: true });
7
6
  exports.runNextjsWizard = runNextjsWizard;
8
- const chalk_1 = __importDefault(require("chalk"));
7
+ /* eslint-disable max-lines */
9
8
  const clack_utils_1 = require("../utils/clack-utils");
10
9
  const package_json_1 = require("../utils/package-json");
11
10
  const utils_1 = require("./utils");
@@ -16,6 +15,8 @@ const analytics_1 = require("../utils/analytics");
16
15
  const environment_1 = require("../utils/environment");
17
16
  const file_utils_1 = require("../utils/file-utils");
18
17
  const clack_utils_2 = require("../utils/clack-utils");
18
+ const add_editor_rules_1 = require("../utils/rules/add-editor-rules");
19
+ const messages_1 = require("../lib/messages");
19
20
  async function runNextjsWizard(options) {
20
21
  (0, clack_utils_1.printWelcome)({
21
22
  wizardName: 'PostHog Next.js Wizard',
@@ -85,6 +86,7 @@ async function runNextjsWizard(options) {
85
86
  await (0, environment_1.addOrUpdateEnvironmentVariables)({
86
87
  variables: {
87
88
  NEXT_PUBLIC_POSTHOG_KEY: projectApiKey,
89
+ NEXT_PUBLIC_POSTHOG_HOST: host,
88
90
  },
89
91
  installDir: options.installDir,
90
92
  integration: constants_1.Integration.nextjs,
@@ -94,12 +96,20 @@ async function runNextjsWizard(options) {
94
96
  installDir: options.installDir,
95
97
  integration: constants_1.Integration.nextjs,
96
98
  });
97
- clack_1.default.outro(`
98
- ${chalk_1.default.green('Successfully installed PostHog!')} ${`\n\n${aiConsent
99
- ? `Note: This uses experimental AI to setup your project. It might have got it wrong, please check!\n`
100
- : ``}You should validate your setup by (re)starting your dev environment (e.g. ${chalk_1.default.cyan(`${packageManagerForOutro.runScriptCommand} dev`)})`}
101
-
102
- ${chalk_1.default.dim(`If you encounter any issues, let us know here: ${constants_1.ISSUES_URL}`)}`);
99
+ const addedEditorRules = await (0, add_editor_rules_1.addEditorRules)({
100
+ rulesName: 'next-rules.md',
101
+ installDir: options.installDir,
102
+ integration: constants_1.Integration.nextjs,
103
+ default: options.default,
104
+ });
105
+ const outroMessage = (0, messages_1.getOutroMessage)({
106
+ options,
107
+ integration: constants_1.Integration.nextjs,
108
+ cloudRegion,
109
+ addedEditorRules,
110
+ packageManager: packageManagerForOutro,
111
+ });
112
+ clack_1.default.outro(outroMessage);
103
113
  await analytics_1.analytics.shutdown('success');
104
114
  }
105
115
  function getInstallationDocumentation({ router, host, language, }) {
@@ -1 +1 @@
1
- {"version":3,"file":"nextjs-wizard.js","sourceRoot":"","sources":["../../../src/nextjs/nextjs-wizard.ts"],"names":[],"mappings":";AAAA,8BAA8B;;;;;AAoC9B,0CAyHC;AA3JD,kDAA0B;AAC1B,sDAY8B;AAC9B,wDAA+E;AAC/E,mCAKiB;AACjB,2DAAmC;AACnC,gDAA2D;AAC3D,iCAA0E;AAC1E,kDAA+C;AAC/C,sDAAuE;AACvE,oDAI6B;AAE7B,sDAAyD;AAElD,KAAK,UAAU,eAAe,CAAC,OAAsB;IAC1D,IAAA,0BAAY,EAAC;QACX,UAAU,EAAE,wBAAwB;KACrC,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,MAAM,IAAA,6BAAe,EAAC,OAAO,CAAC,CAAC;IAEjD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAA,mBAAK,EACT,2JAA2J,EAC3J,CAAC,CACF,CAAC;IACJ,CAAC;IAED,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,CAAC,MAAM,IAAA,+BAAiB,GAAE,CAAC,CAAC;IAEvE,MAAM,kBAAkB,GAAG,IAAA,+BAAiB,EAAC,OAAO,CAAC,CAAC;IAEtD,MAAM,IAAA,+CAAiC,EAAC,OAAO,CAAC,CAAC;IAEjD,MAAM,WAAW,GAAG,MAAM,IAAA,+BAAiB,EAAC,OAAO,CAAC,CAAC;IAErD,MAAM,IAAA,sCAAwB,EAAC,WAAW,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IAE/D,MAAM,WAAW,GAAG,IAAA,gCAAiB,EAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAE3D,qBAAS,CAAC,MAAM,CAAC,gBAAgB,EAAE,IAAA,8BAAsB,EAAC,WAAW,CAAC,CAAC,CAAC;IAExE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,MAAM,IAAA,oCAAsB,EA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S,CAAC,CAAC;AACtC,CAAC;AAED,SAAS,4BAA4B,CAAC,EACpC,MAAM,EACN,IAAI,EACJ,QAAQ,GAKT;IACC,IAAI,MAAM,KAAK,oBAAY,CAAC,YAAY,EAAE,CAAC;QACzC,OAAO,IAAA,+BAAwB,EAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;IACtD,CAAC;IAED,OAAO,IAAA,6BAAsB,EAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;AACpD,CAAC","sourcesContent":["/* eslint-disable max-lines */\n\nimport chalk from 'chalk';\nimport {\n abort,\n askForAIConsent,\n confirmContinueIfNoOrDirtyGitRepo,\n ensurePackageIsInstalled,\n getOrAskForProjectData,\n getPackageDotJson,\n getPackageManager,\n installPackage,\n isUsingTypeScript,\n printWelcome,\n runPrettierIfInstalled,\n} from '../utils/clack-utils';\nimport { getPackageVersion, hasPackageInstalled } from '../utils/package-json';\nimport {\n getNextJsRouter,\n getNextJsRouterName,\n getNextJsVersionBucket,\n NextJsRouter,\n} from './utils';\nimport clack from '../utils/clack';\nimport { Integration, ISSUES_URL } from '../lib/constants';\nimport { getNextjsAppRouterDocs, getNextjsPagesRouterDocs } from './docs';\nimport { analytics } from '../utils/analytics';\nimport { addOrUpdateEnvironmentVariables } from '../utils/environment';\nimport {\n generateFileChangesForIntegration,\n getFilesToChange,\n getRelevantFilesForIntegration,\n} from '../utils/file-utils';\nimport type { WizardOptions } from '../utils/types';\nimport { askForCloudRegion } from '../utils/clack-utils';\n\nexport async function runNextjsWizard(options: WizardOptions): Promise<void> {\n printWelcome({\n wizardName: 'PostHog Next.js Wizard',\n });\n\n const aiConsent = await askForAIConsent(options);\n\n if (!aiConsent) {\n await abort(\n 'The Next.js wizard requires AI to get setup right now. Please view the docs to setup Next.js manually instead: https://posthog.com/docs/libraries/next-js',\n 0,\n );\n }\n\n const cloudRegion = options.cloudRegion ?? (await askForCloudRegion());\n\n const typeScriptDetected = isUsingTypeScript(options);\n\n await confirmContinueIfNoOrDirtyGitRepo(options);\n\n const packageJson = await getPackageDotJson(options);\n\n await ensurePackageIsInstalled(packageJson, 'next', 'Next.js');\n\n const nextVersion = getPackageVersion('next', packageJson);\n\n analytics.setTag('nextjs-version', getNextJsVersionBucket(nextVersion));\n\n const { projectApiKey, wizardHash, host } = await getOrAskForProjectData({\n ...options,\n cloudRegion,\n });\n\n const sdkAlreadyInstalled = hasPackageInstalled('posthog-js', packageJson);\n\n analytics.setTag('sdk-already-installed', sdkAlreadyInstalled);\n\n const { packageManager: packageManagerFromInstallStep } =\n await installPackage({\n packageName: 'posthog-js',\n packageNameDisplayLabel: 'posthog-js',\n alreadyInstalled: !!packageJson?.dependencies?.['posthog-js'],\n forceInstall: options.forceInstall,\n askBeforeUpdating: false,\n installDir: options.installDir,\n integration: Integration.nextjs,\n });\n\n await installPackage({\n packageName: 'posthog-node',\n packageNameDisplayLabel: 'posthog-node',\n packageManager: packageManagerFromInstallStep,\n alreadyInstalled: !!packageJson?.dependencies?.['posthog-node'],\n forceInstall: options.forceInstall,\n askBeforeUpdating: false,\n installDir: options.installDir,\n integration: Integration.nextjs,\n });\n\n const router = await getNextJsRouter(options);\n\n const relevantFiles = await getRelevantFilesForIntegration({\n installDir: options.installDir,\n integration: Integration.nextjs,\n });\n\n const installationDocumentation = getInstallationDocumentation({\n router,\n host,\n language: typeScriptDetected ? 'typescript' : 'javascript',\n });\n\n clack.log.info(\n `Reviewing PostHog documentation for ${getNextJsRouterName(router)}`,\n );\n\n const filesToChange = await getFilesToChange({\n integration: Integration.nextjs,\n relevantFiles,\n documentation: installationDocumentation,\n wizardHash,\n cloudRegion,\n });\n\n await generateFileChangesForIntegration({\n integration: Integration.nextjs,\n filesToChange,\n wizardHash,\n installDir: options.installDir,\n documentation: installationDocumentation,\n cloudRegion,\n });\n\n await addOrUpdateEnvironmentVariables({\n variables: {\n NEXT_PUBLIC_POSTHOG_KEY: projectApiKey,\n },\n installDir: options.installDir,\n integration: Integration.nextjs,\n });\n\n const packageManagerForOutro =\n packageManagerFromInstallStep ?? (await getPackageManager(options));\n\n await runPrettierIfInstalled({\n installDir: options.installDir,\n integration: Integration.nextjs,\n });\n\n clack.outro(`\n${chalk.green('Successfully installed PostHog!')} ${`\\n\\n${\n aiConsent\n ? `Note: This uses experimental AI to setup your project. It might have got it wrong, please check!\\n`\n : ``\n }You should validate your setup by (re)starting your dev environment (e.g. ${chalk.cyan(\n `${packageManagerForOutro.runScriptCommand} dev`,\n )})`}\n\n${chalk.dim(`If you encounter any issues, let us know here: ${ISSUES_URL}`)}`);\n\n await analytics.shutdown('success');\n}\n\nfunction getInstallationDocumentation({\n router,\n host,\n language,\n}: {\n router: NextJsRouter;\n host: string;\n language: 'typescript' | 'javascript';\n}) {\n if (router === NextJsRouter.PAGES_ROUTER) {\n return getNextjsPagesRouterDocs({ host, language });\n }\n\n return getNextjsAppRouterDocs({ host, language });\n}\n"]}
1
+ {"version":3,"file":"nextjs-wizard.js","sourceRoot":"","sources":["../../../src/nextjs/nextjs-wizard.ts"],"names":[],"mappings":";;;;;AAoCA,0CAgIC;AApKD,8BAA8B;AAC9B,sDAY8B;AAC9B,wDAA+E;AAC/E,mCAKiB;AACjB,2DAAmC;AACnC,gDAA+C;AAC/C,iCAA0E;AAC1E,kDAA+C;AAC/C,sDAAuE;AACvE,oDAI6B;AAE7B,sDAAyD;AACzD,sEAAiE;AACjE,8CAAkD;AAE3C,KAAK,UAAU,eAAe,CAAC,OAAsB;IAC1D,IAAA,0BAAY,EAAC;QACX,UAAU,EAAE,wBAAwB;KACrC,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,MAAM,IAAA,6BAAe,EAAC,OAAO,CAAC,CAAC;IAEjD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAA,mBAAK,EACT,2JAA2J,EAC3J,CAAC,CACF,CAAC;IACJ,CAAC;IAED,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,CAAC,MAAM,IAAA,+B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H,MAAM,sBAAsB,GAC1B,6BAA6B,IAAI,CAAC,MAAM,IAAA,+BAAiB,EAAC,OAAO,CAAC,CAAC,CAAC;IAEtE,MAAM,IAAA,oCAAsB,EAAC;QAC3B,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,WAAW,EAAE,uBAAW,CAAC,MAAM;KAChC,CAAC,CAAC;IAEH,MAAM,gBAAgB,GAAG,MAAM,IAAA,iCAAc,EAAC;QAC5C,SAAS,EAAE,eAAe;QAC1B,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,WAAW,EAAE,uBAAW,CAAC,MAAM;QAC/B,OAAO,EAAE,OAAO,CAAC,OAAO;KACzB,CAAC,CAAC;IAEH,MAAM,YAAY,GAAG,IAAA,0BAAe,EAAC;QACnC,OAAO;QACP,WAAW,EAAE,uBAAW,CAAC,MAAM;QAC/B,WAAW;QACX,gBAAgB;QAChB,cAAc,EAAE,sBAAsB;KACvC,CAAC,CAAC;IAEH,eAAK,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IAE1B,MAAM,qBAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AACtC,CAAC;AAED,SAAS,4BAA4B,CAAC,EACpC,MAAM,EACN,IAAI,EACJ,QAAQ,GAKT;IACC,IAAI,MAAM,KAAK,oBAAY,CAAC,YAAY,EAAE,CAAC;QACzC,OAAO,IAAA,+BAAwB,EAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;IACtD,CAAC;IAED,OAAO,IAAA,6BAAsB,EAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;AACpD,CAAC","sourcesContent":["/* eslint-disable max-lines */\nimport {\n abort,\n askForAIConsent,\n confirmContinueIfNoOrDirtyGitRepo,\n ensurePackageIsInstalled,\n getOrAskForProjectData,\n getPackageDotJson,\n getPackageManager,\n installPackage,\n isUsingTypeScript,\n printWelcome,\n runPrettierIfInstalled,\n} from '../utils/clack-utils';\nimport { getPackageVersion, hasPackageInstalled } from '../utils/package-json';\nimport {\n getNextJsRouter,\n getNextJsRouterName,\n getNextJsVersionBucket,\n NextJsRouter,\n} from './utils';\nimport clack from '../utils/clack';\nimport { Integration } from '../lib/constants';\nimport { getNextjsAppRouterDocs, getNextjsPagesRouterDocs } from './docs';\nimport { analytics } from '../utils/analytics';\nimport { addOrUpdateEnvironmentVariables } from '../utils/environment';\nimport {\n generateFileChangesForIntegration,\n getFilesToChange,\n getRelevantFilesForIntegration,\n} from '../utils/file-utils';\nimport type { WizardOptions } from '../utils/types';\nimport { askForCloudRegion } from '../utils/clack-utils';\nimport { addEditorRules } from '../utils/rules/add-editor-rules';\nimport { getOutroMessage } from '../lib/messages';\n\nexport async function runNextjsWizard(options: WizardOptions): Promise<void> {\n printWelcome({\n wizardName: 'PostHog Next.js Wizard',\n });\n\n const aiConsent = await askForAIConsent(options);\n\n if (!aiConsent) {\n await abort(\n 'The Next.js wizard requires AI to get setup right now. Please view the docs to setup Next.js manually instead: https://posthog.com/docs/libraries/next-js',\n 0,\n );\n }\n\n const cloudRegion = options.cloudRegion ?? (await askForCloudRegion());\n\n const typeScriptDetected = isUsingTypeScript(options);\n\n await confirmContinueIfNoOrDirtyGitRepo(options);\n\n const packageJson = await getPackageDotJson(options);\n\n await ensurePackageIsInstalled(packageJson, 'next', 'Next.js');\n\n const nextVersion = getPackageVersion('next', packageJson);\n\n analytics.setTag('nextjs-version', getNextJsVersionBucket(nextVersion));\n\n const { projectApiKey, wizardHash, host } = await getOrAskForProjectData({\n ...options,\n cloudRegion,\n });\n\n const sdkAlreadyInstalled = hasPackageInstalled('posthog-js', packageJson);\n\n analytics.setTag('sdk-already-installed', sdkAlreadyInstalled);\n\n const { packageManager: packageManagerFromInstallStep } =\n await installPackage({\n packageName: 'posthog-js',\n packageNameDisplayLabel: 'posthog-js',\n alreadyInstalled: !!packageJson?.dependencies?.['posthog-js'],\n forceInstall: options.forceInstall,\n askBeforeUpdating: false,\n installDir: options.installDir,\n integration: Integration.nextjs,\n });\n\n await installPackage({\n packageName: 'posthog-node',\n packageNameDisplayLabel: 'posthog-node',\n packageManager: packageManagerFromInstallStep,\n alreadyInstalled: !!packageJson?.dependencies?.['posthog-node'],\n forceInstall: options.forceInstall,\n askBeforeUpdating: false,\n installDir: options.installDir,\n integration: Integration.nextjs,\n });\n\n const router = await getNextJsRouter(options);\n\n const relevantFiles = await getRelevantFilesForIntegration({\n installDir: options.installDir,\n integration: Integration.nextjs,\n });\n\n const installationDocumentation = getInstallationDocumentation({\n router,\n host,\n language: typeScriptDetected ? 'typescript' : 'javascript',\n });\n\n clack.log.info(\n `Reviewing PostHog documentation for ${getNextJsRouterName(router)}`,\n );\n\n const filesToChange = await getFilesToChange({\n integration: Integration.nextjs,\n relevantFiles,\n documentation: installationDocumentation,\n wizardHash,\n cloudRegion,\n });\n\n await generateFileChangesForIntegration({\n integration: Integration.nextjs,\n filesToChange,\n wizardHash,\n installDir: options.installDir,\n documentation: installationDocumentation,\n cloudRegion,\n });\n\n await addOrUpdateEnvironmentVariables({\n variables: {\n NEXT_PUBLIC_POSTHOG_KEY: projectApiKey,\n NEXT_PUBLIC_POSTHOG_HOST: host,\n },\n installDir: options.installDir,\n integration: Integration.nextjs,\n });\n\n const packageManagerForOutro =\n packageManagerFromInstallStep ?? (await getPackageManager(options));\n\n await runPrettierIfInstalled({\n installDir: options.installDir,\n integration: Integration.nextjs,\n });\n\n const addedEditorRules = await addEditorRules({\n rulesName: 'next-rules.md',\n installDir: options.installDir,\n integration: Integration.nextjs,\n default: options.default,\n });\n\n const outroMessage = getOutroMessage({\n options,\n integration: Integration.nextjs,\n cloudRegion,\n addedEditorRules,\n packageManager: packageManagerForOutro,\n });\n\n clack.outro(outroMessage);\n\n await analytics.shutdown('success');\n}\n\nfunction getInstallationDocumentation({\n router,\n host,\n language,\n}: {\n router: NextJsRouter;\n host: string;\n language: 'typescript' | 'javascript';\n}) {\n if (router === NextJsRouter.PAGES_ROUTER) {\n return getNextjsPagesRouterDocs({ host, language });\n }\n\n return getNextjsAppRouterDocs({ host, language });\n}\n"]}
@@ -1,5 +1,4 @@
1
- export declare const getReactDocumentation: ({ host, language, envVarPrefix, }: {
2
- host: string;
1
+ export declare const getReactDocumentation: ({ language, envVarPrefix, }: {
3
2
  language: "typescript" | "javascript";
4
3
  envVarPrefix: string;
5
4
  }) => string;
@@ -1,10 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getReactDocumentation = void 0;
4
- const getReactDocumentation = ({ host, language, envVarPrefix, }) => {
4
+ const getReactDocumentation = ({ language, envVarPrefix, }) => {
5
5
  const apiKeyText = envVarPrefix === 'VITE_PUBLIC_'
6
6
  ? 'import.meta.env.VITE_PUBLIC_POSTHOG_KEY'
7
7
  : `process.env.${envVarPrefix}POSTHOG_KEY`;
8
+ const hostText = envVarPrefix === 'VITE_PUBLIC_'
9
+ ? 'import.meta.env.VITE_PUBLIC_POSTHOG_HOST'
10
+ : `process.env.${envVarPrefix}POSTHOG_HOST`;
8
11
  return `
9
12
  ==============================
10
13
  FILE: {index / App}.${language === 'typescript' ? 'tsx' : 'jsx'} (wherever the root of the app is)
@@ -28,8 +31,11 @@ root.render(
28
31
  <PostHogProvider
29
32
  apiKey={${apiKeyText}}
30
33
  options={{
31
- api_host: ${host},
32
- }}
34
+ api_host: ${hostText},
35
+ debug: ${envVarPrefix === 'VITE_PUBLIC_'
36
+ ? 'import.meta.env.MODE === "development"'
37
+ : 'process.env.NODE_ENV === "development"'},
38
+ }}
33
39
  >
34
40
  <App />
35
41
  </PostHogProvider>
@@ -1 +1 @@
1
- {"version":3,"file":"docs.js","sourceRoot":"","sources":["../../../src/react/docs.ts"],"names":[],"mappings":";;;AAAO,MAAM,qBAAqB,GAAG,CAAC,EACpC,IAAI,EACJ,QAAQ,EACR,YAAY,GAKb,EAAE,EAAE;IACH,MAAM,UAAU,GACd,YAAY,KAAK,cAAc;QAC7B,CAAC,CAAC,yCAAyC;QAC3C,CAAC,CAAC,eAAe,YAAY,aAAa,CAAC;IAC/C,OAAO;;sBAGL,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KACtC;;;;;;;;;;;;;;;;;;;gBAmBc,UAAU;;cAEZ,IAAI;;;;;;mDAMiC,CAAC;AACpD,CAAC,CAAC;AA7CW,QAAA,qBAAqB,yBA6ChC","sourcesContent":["export const getReactDocumentation = ({\n host,\n language,\n envVarPrefix,\n}: {\n host: string;\n language: 'typescript' | 'javascript';\n envVarPrefix: string;\n}) => {\n const apiKeyText =\n envVarPrefix === 'VITE_PUBLIC_'\n ? 'import.meta.env.VITE_PUBLIC_POSTHOG_KEY'\n : `process.env.${envVarPrefix}POSTHOG_KEY`;\n return `\n==============================\nFILE: {index / App}.${\n language === 'typescript' ? 'tsx' : 'jsx'\n } (wherever the root of the app is)\nLOCATION: Wherever the root of the app is\n==============================\nChanges:\n- Add the PostHogProvider to the root of the app in the provider tree.\n\nExample:\n--------------------------------------------------\nimport React from 'react';\nimport ReactDOM from 'react-dom/client';\nimport App from './App';\n\nimport { PostHogProvider} from 'posthog-js/react'\n\nconst root = ReactDOM.createRoot(document.getElementById('root'));\n\nroot.render(\n <React.StrictMode>\n <PostHogProvider\n apiKey={${apiKeyText}}\n options={{\n api_host: ${host},\n}}\n >\n <App />\n </PostHogProvider>\n </React.StrictMode>\n--------------------------------------------------`;\n};\n"]}
1
+ {"version":3,"file":"docs.js","sourceRoot":"","sources":["../../../src/react/docs.ts"],"names":[],"mappings":";;;AAAO,MAAM,qBAAqB,GAAG,CAAC,EACpC,QAAQ,EACR,YAAY,GAIb,EAAE,EAAE;IACH,MAAM,UAAU,GACd,YAAY,KAAK,cAAc;QAC7B,CAAC,CAAC,yCAAyC;QAC3C,CAAC,CAAC,eAAe,YAAY,aAAa,CAAC;IAE/C,MAAM,QAAQ,GACZ,YAAY,KAAK,cAAc;QAC7B,CAAC,CAAC,0CAA0C;QAC5C,CAAC,CAAC,eAAe,YAAY,cAAc,CAAC;IAEhD,OAAO;;sBAGL,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KACtC;;;;;;;;;;;;;;;;;;;gBAmBc,UAAU;;oBAEN,QAAQ;iBAElB,YAAY,KAAK,cAAc;QAC7B,CAAC,CAAC,wCAAwC;QAC1C,CAAC,CAAC,wCACN;;;;;;mDAM2C,CAAC;AACpD,CAAC,CAAC;AAtDW,QAAA,qBAAqB,yBAsDhC","sourcesContent":["export const getReactDocumentation = ({\n language,\n envVarPrefix,\n}: {\n language: 'typescript' | 'javascript';\n envVarPrefix: string;\n}) => {\n const apiKeyText =\n envVarPrefix === 'VITE_PUBLIC_'\n ? 'import.meta.env.VITE_PUBLIC_POSTHOG_KEY'\n : `process.env.${envVarPrefix}POSTHOG_KEY`;\n\n const hostText =\n envVarPrefix === 'VITE_PUBLIC_'\n ? 'import.meta.env.VITE_PUBLIC_POSTHOG_HOST'\n : `process.env.${envVarPrefix}POSTHOG_HOST`;\n\n return `\n==============================\nFILE: {index / App}.${\n language === 'typescript' ? 'tsx' : 'jsx'\n } (wherever the root of the app is)\nLOCATION: Wherever the root of the app is\n==============================\nChanges:\n- Add the PostHogProvider to the root of the app in the provider tree.\n\nExample:\n--------------------------------------------------\nimport React from 'react';\nimport ReactDOM from 'react-dom/client';\nimport App from './App';\n\nimport { PostHogProvider} from 'posthog-js/react'\n\nconst root = ReactDOM.createRoot(document.getElementById('root'));\n\nroot.render(\n <React.StrictMode>\n <PostHogProvider\n apiKey={${apiKeyText}}\n options={{\n api_host: ${hostText},\n debug: ${\n envVarPrefix === 'VITE_PUBLIC_'\n ? 'import.meta.env.MODE === \"development\"'\n : 'process.env.NODE_ENV === \"development\"'\n },\n }}\n >\n <App />\n </PostHogProvider>\n </React.StrictMode>\n--------------------------------------------------`;\n};\n"]}