@posthog/wizard 0.5.0 → 0.7.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 (90) hide show
  1. package/README.md +21 -15
  2. package/package.json +1 -1
  3. package/dist/bin.d.ts +0 -2
  4. package/dist/bin.js +0 -28
  5. package/dist/bin.js.map +0 -1
  6. package/dist/src/lib/config.d.ts +0 -21
  7. package/dist/src/lib/config.js +0 -49
  8. package/dist/src/lib/config.js.map +0 -1
  9. package/dist/src/lib/constants.d.ts +0 -22
  10. package/dist/src/lib/constants.js +0 -40
  11. package/dist/src/lib/constants.js.map +0 -1
  12. package/dist/src/lib/prompts.d.ts +0 -16
  13. package/dist/src/lib/prompts.js +0 -80
  14. package/dist/src/lib/prompts.js.map +0 -1
  15. package/dist/src/nextjs/docs.d.ts +0 -8
  16. package/dist/src/nextjs/docs.js +0 -257
  17. package/dist/src/nextjs/docs.js.map +0 -1
  18. package/dist/src/nextjs/nextjs-wizard.d.ts +0 -2
  19. package/dist/src/nextjs/nextjs-wizard.js +0 -117
  20. package/dist/src/nextjs/nextjs-wizard.js.map +0 -1
  21. package/dist/src/nextjs/utils.d.ts +0 -9
  22. package/dist/src/nextjs/utils.js +0 -83
  23. package/dist/src/nextjs/utils.js.map +0 -1
  24. package/dist/src/react/docs.d.ts +0 -5
  25. package/dist/src/react/docs.js +0 -43
  26. package/dist/src/react/docs.js.map +0 -1
  27. package/dist/src/react/react-wizard.d.ts +0 -2
  28. package/dist/src/react/react-wizard.js +0 -103
  29. package/dist/src/react/react-wizard.js.map +0 -1
  30. package/dist/src/run.d.ts +0 -12
  31. package/dist/src/run.js +0 -72
  32. package/dist/src/run.js.map +0 -1
  33. package/dist/src/telemetry.d.ts +0 -2
  34. package/dist/src/telemetry.js +0 -13
  35. package/dist/src/telemetry.js.map +0 -1
  36. package/dist/src/utils/analytics.d.ts +0 -12
  37. package/dist/src/utils/analytics.js +0 -59
  38. package/dist/src/utils/analytics.js.map +0 -1
  39. package/dist/src/utils/bash.d.ts +0 -2
  40. package/dist/src/utils/bash.js +0 -54
  41. package/dist/src/utils/bash.js.map +0 -1
  42. package/dist/src/utils/clack-utils.d.ts +0 -184
  43. package/dist/src/utils/clack-utils.js +0 -678
  44. package/dist/src/utils/clack-utils.js.map +0 -1
  45. package/dist/src/utils/clack.d.ts +0 -2
  46. package/dist/src/utils/clack.js +0 -9
  47. package/dist/src/utils/clack.js.map +0 -1
  48. package/dist/src/utils/debug.d.ts +0 -2
  49. package/dist/src/utils/debug.js +0 -22
  50. package/dist/src/utils/debug.js.map +0 -1
  51. package/dist/src/utils/environment.d.ts +0 -9
  52. package/dist/src/utils/environment.js +0 -164
  53. package/dist/src/utils/environment.js.map +0 -1
  54. package/dist/src/utils/file-utils.d.ts +0 -29
  55. package/dist/src/utils/file-utils.js +0 -177
  56. package/dist/src/utils/file-utils.js.map +0 -1
  57. package/dist/src/utils/logging.d.ts +0 -9
  58. package/dist/src/utils/logging.js +0 -50
  59. package/dist/src/utils/logging.js.map +0 -1
  60. package/dist/src/utils/package-json.d.ts +0 -25
  61. package/dist/src/utils/package-json.js +0 -27
  62. package/dist/src/utils/package-json.js.map +0 -1
  63. package/dist/src/utils/package-manager.d.ts +0 -20
  64. package/dist/src/utils/package-manager.js +0 -187
  65. package/dist/src/utils/package-manager.js.map +0 -1
  66. package/dist/src/utils/query.d.ts +0 -8
  67. package/dist/src/utils/query.js +0 -27
  68. package/dist/src/utils/query.js.map +0 -1
  69. package/dist/src/utils/rules/add-editor-rules.d.ts +0 -9
  70. package/dist/src/utils/rules/add-editor-rules.js +0 -88
  71. package/dist/src/utils/rules/add-editor-rules.js.map +0 -1
  72. package/dist/src/utils/rules/add-editor-rules.ts +0 -82
  73. package/dist/src/utils/rules/next-rules.md +0 -9
  74. package/dist/src/utils/rules/react-rules.md +0 -7
  75. package/dist/src/utils/rules/universal.md +0 -20
  76. package/dist/src/utils/semver.d.ts +0 -5
  77. package/dist/src/utils/semver.js +0 -25
  78. package/dist/src/utils/semver.js.map +0 -1
  79. package/dist/src/utils/string.d.ts +0 -1
  80. package/dist/src/utils/string.js +0 -9
  81. package/dist/src/utils/string.js.map +0 -1
  82. package/dist/src/utils/types.d.ts +0 -44
  83. package/dist/src/utils/types.js +0 -3
  84. package/dist/src/utils/types.js.map +0 -1
  85. package/dist/src/utils/urls.d.ts +0 -4
  86. package/dist/src/utils/urls.js +0 -35
  87. package/dist/src/utils/urls.js.map +0 -1
  88. package/dist/src/utils/vendor/is-unicorn-supported.d.ts +0 -1
  89. package/dist/src/utils/vendor/is-unicorn-supported.js +0 -24
  90. package/dist/src/utils/vendor/is-unicorn-supported.js.map +0 -1
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
+ > 💖
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posthog/wizard",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "homepage": "https://github.com/posthog/wizard",
5
5
  "repository": "https://github.com/posthog/wizard",
6
6
  "description": "The PostHog wizard helps you to configure your project",
package/dist/bin.d.ts DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
package/dist/bin.js DELETED
@@ -1,28 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- const semver_1 = require("semver");
8
- const logging_1 = require("./src/utils/logging");
9
- const yargs_1 = __importDefault(require("yargs"));
10
- const helpers_1 = require("yargs/helpers");
11
- const NODE_VERSION_RANGE = '>=18.20.0';
12
- // Have to run this above the other imports because they are importing clack that
13
- // has the problematic imports.
14
- if (!(0, semver_1.satisfies)(process.version, NODE_VERSION_RANGE)) {
15
- (0, logging_1.red)(`PostHog Wizard requires Node.js ${NODE_VERSION_RANGE}. You are using Node.js ${process.version}. Please upgrade your Node.js version.`);
16
- process.exit(1);
17
- }
18
- const run_1 = require("./src/run");
19
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
20
- const argv = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv)).options({
21
- debug: {
22
- default: false,
23
- describe: 'Enable verbose logging\nenv: POSTHOG_WIZARD_DEBUG',
24
- type: 'boolean',
25
- },
26
- }).argv;
27
- void (0, run_1.run)(argv);
28
- //# sourceMappingURL=bin.js.map
package/dist/bin.js.map DELETED
@@ -1 +0,0 @@
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,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AACD,mCAAgC;AAEhC,kJAAkJ;AAClJ,MAAM,IAAI,GAAG,IAAA,eAAK,EAAC,IAAA,iBAAO,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;IAChD,KAAK,EAAE;QACL,OAAO,EAAE,KAAK;QACd,QAAQ,EAAE,mDAAmD;QAC7D,IAAI,EAAE,SAAS;KAChB;CACF,CAAC,CAAC,IAAI,CAAC;AAER,KAAK,IAAA,SAAG,EAAC,IAAI,CAAC,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.20.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}\nimport { run } from './src/run';\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\nconst argv = yargs(hideBin(process.argv)).options({\n debug: {\n default: false,\n describe: 'Enable verbose logging\\nenv: POSTHOG_WIZARD_DEBUG',\n type: 'boolean',\n },\n}).argv;\n\nvoid run(argv);\n"]}
@@ -1,21 +0,0 @@
1
- import type { WizardOptions } from '../utils/types';
2
- import { Integration } from './constants';
3
- export declare const INTEGRATION_CONFIG: {
4
- readonly nextjs: {
5
- readonly name: "Next.js";
6
- readonly filterPatterns: ["**/*.{tsx,ts,jsx,js,mjs,cjs}"];
7
- readonly ignorePatterns: ["node_modules", "dist", "build", "public", "static", "next-env.d.*"];
8
- readonly detect: (options: Pick<WizardOptions, "installDir">) => Promise<boolean>;
9
- readonly generateFilesRules: "";
10
- readonly filterFilesRules: "";
11
- };
12
- readonly react: {
13
- readonly name: "React";
14
- readonly filterPatterns: ["**/*.{tsx,ts,jsx,js}"];
15
- readonly ignorePatterns: ["node_modules", "dist", "build", "public", "static", "assets"];
16
- readonly detect: (options: Pick<WizardOptions, "installDir">) => Promise<boolean>;
17
- readonly generateFilesRules: "";
18
- readonly filterFilesRules: "";
19
- };
20
- };
21
- export declare const INTEGRATION_ORDER: readonly [Integration.nextjs, Integration.react];
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.INTEGRATION_ORDER = exports.INTEGRATION_CONFIG = void 0;
4
- const clack_utils_1 = require("../utils/clack-utils");
5
- const package_json_1 = require("../utils/package-json");
6
- const constants_1 = require("./constants");
7
- exports.INTEGRATION_CONFIG = {
8
- [constants_1.Integration.nextjs]: {
9
- name: 'Next.js',
10
- filterPatterns: ['**/*.{tsx,ts,jsx,js,mjs,cjs}'],
11
- ignorePatterns: [
12
- 'node_modules',
13
- 'dist',
14
- 'build',
15
- 'public',
16
- 'static',
17
- 'next-env.d.*',
18
- ],
19
- detect: async (options) => {
20
- const packageJson = await (0, clack_utils_1.getPackageDotJson)(options);
21
- return (0, package_json_1.hasPackageInstalled)('next', packageJson);
22
- },
23
- generateFilesRules: '',
24
- filterFilesRules: '',
25
- },
26
- [constants_1.Integration.react]: {
27
- name: 'React',
28
- filterPatterns: ['**/*.{tsx,ts,jsx,js}'],
29
- ignorePatterns: [
30
- 'node_modules',
31
- 'dist',
32
- 'build',
33
- 'public',
34
- 'static',
35
- 'assets',
36
- ],
37
- detect: async (options) => {
38
- const packageJson = await (0, clack_utils_1.getPackageDotJson)(options);
39
- return (0, package_json_1.hasPackageInstalled)('react', packageJson);
40
- },
41
- generateFilesRules: '',
42
- filterFilesRules: '',
43
- },
44
- };
45
- exports.INTEGRATION_ORDER = [
46
- constants_1.Integration.nextjs,
47
- constants_1.Integration.react,
48
- ];
49
- //# sourceMappingURL=config.js.map
@@ -1 +0,0 @@
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,22 +0,0 @@
1
- export declare enum Integration {
2
- nextjs = "nextjs",
3
- react = "react"
4
- }
5
- export declare function getIntegrationDescription(type: string): string;
6
- type IntegrationChoice = {
7
- name: string;
8
- value: string;
9
- };
10
- export declare function getIntegrationChoices(): IntegrationChoice[];
11
- export interface Args {
12
- debug: boolean;
13
- integration: Integration;
14
- }
15
- export declare const IS_DEV = false;
16
- export declare const DEFAULT_URL: string;
17
- export declare const ISSUES_URL = "https://github.com/posthog/wizard/issues";
18
- export declare const DEFAULT_HOST_URL: string;
19
- export declare const ANALYTICS_POSTHOG_PUBLIC_PROJECT_WRITE_KEY = "sTMFPsFhdP1Ssg";
20
- export declare const ANALYTICS_HOST_URL: string;
21
- export declare const DUMMY_PROJECT_API_KEY = "_YOUR_POSTHOG_PROJECT_API_KEY_";
22
- export {};
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DUMMY_PROJECT_API_KEY = exports.ANALYTICS_HOST_URL = exports.ANALYTICS_POSTHOG_PUBLIC_PROJECT_WRITE_KEY = exports.DEFAULT_HOST_URL = exports.ISSUES_URL = exports.DEFAULT_URL = exports.IS_DEV = exports.Integration = void 0;
4
- exports.getIntegrationDescription = getIntegrationDescription;
5
- exports.getIntegrationChoices = getIntegrationChoices;
6
- var Integration;
7
- (function (Integration) {
8
- Integration["nextjs"] = "nextjs";
9
- Integration["react"] = "react";
10
- })(Integration || (exports.Integration = Integration = {}));
11
- function getIntegrationDescription(type) {
12
- switch (type) {
13
- case Integration.nextjs:
14
- return 'Next.js';
15
- case Integration.react:
16
- return 'React';
17
- default:
18
- throw new Error(`Unknown integration ${type}`);
19
- }
20
- }
21
- function getIntegrationChoices() {
22
- return Object.keys(Integration).map((type) => ({
23
- name: getIntegrationDescription(type),
24
- value: type,
25
- }));
26
- }
27
- exports.IS_DEV = false;
28
- exports.DEFAULT_URL = exports.IS_DEV
29
- ? 'http://localhost:8010'
30
- : 'https://us.posthog.com';
31
- exports.ISSUES_URL = 'https://github.com/posthog/wizard/issues';
32
- exports.DEFAULT_HOST_URL = exports.IS_DEV
33
- ? 'http://localhost:8010'
34
- : 'https://us.i.posthog.com';
35
- exports.ANALYTICS_POSTHOG_PUBLIC_PROJECT_WRITE_KEY = 'sTMFPsFhdP1Ssg';
36
- exports.ANALYTICS_HOST_URL = exports.IS_DEV
37
- ? 'http://localhost:8010'
38
- : 'https://internal-t.posthog.com';
39
- exports.DUMMY_PROJECT_API_KEY = '_YOUR_POSTHOG_PROJECT_API_KEY_';
40
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
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,16 +0,0 @@
1
- import { PromptTemplate } from '@langchain/core/prompts';
2
- export declare const baseFilterFilesPromptTemplate: PromptTemplate<{
3
- documentation: any;
4
- file_list: any;
5
- integration_name: any;
6
- integration_rules: any;
7
- }, any>;
8
- export declare const baseGenerateFileChangesPromptTemplate: PromptTemplate<{
9
- documentation: any;
10
- integration_name: any;
11
- integration_rules: any;
12
- file_content: any;
13
- file_path: any;
14
- changed_files: any;
15
- unchanged_files: any;
16
- }, any>;
@@ -1,80 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.baseGenerateFileChangesPromptTemplate = exports.baseFilterFilesPromptTemplate = void 0;
4
- const prompts_1 = require("@langchain/core/prompts");
5
- exports.baseFilterFilesPromptTemplate = new prompts_1.PromptTemplate({
6
- inputVariables: [
7
- 'documentation',
8
- 'file_list',
9
- 'integration_name',
10
- 'integration_rules',
11
- ],
12
- template: `You are a PostHog installation wizard, a master AI programming assistant that implements PostHog for {integration_name} projects.
13
- Given the following list of file paths from a project, determine which files are likely to require modifications
14
- to 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.
15
-
16
- - If you would like to create a new file, you can include the file path in your response.
17
- - If you would like to modify an existing file, you can include the file path in your response.
18
-
19
- You 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.
20
-
21
- Rules:
22
- - Only return files that you think will be required to look at or modify to integrate PostHog.
23
- - Do not return files that are unlikely to require modification based on the documentation.
24
- - If you are unsure, return the file, since it's better to have more files than less.
25
- - If you create a new file, it should not conflict with any existing files.
26
- - 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
- {integration_rules}
29
-
30
- Installation documentation:
31
- {documentation}
32
-
33
- All current files in the repository:
34
-
35
- {file_list}`,
36
- });
37
- exports.baseGenerateFileChangesPromptTemplate = new prompts_1.PromptTemplate({
38
- inputVariables: [
39
- 'file_content',
40
- 'documentation',
41
- 'file_path',
42
- 'changed_files',
43
- 'unchanged_files',
44
- 'integration_name',
45
- 'integration_rules',
46
- ],
47
- template: `You are a PostHog installation wizard, a master AI programming assistant that implements PostHog for {integration_name} projects.
48
-
49
- Your task is to update the file to integrate PostHog according to the documentation.
50
- Do not return a diff — you should return the complete updated file content.
51
-
52
- Rules:
53
- - Preserve the existing code formatting and style.
54
- - Only make the changes required by the documentation.
55
- - If no changes are needed, return the file as-is.
56
- - If the current file is empty, and you think it should be created, you can add the contents of the new file.
57
- - The file structure of the project may be different than the documentation, you should follow the file structure of the project.
58
- - Use relative imports if you are unsure what the project import paths are.
59
- {integration_rules}
60
-
61
-
62
- CONTEXT
63
- ---
64
-
65
- Documentation for integrating PostHog with {integration_name}:
66
- {documentation}
67
-
68
- The file you are updating is:
69
- {file_path}
70
-
71
- Here are the changes you have already made to the project:
72
- {changed_files}
73
-
74
- Here are the files that have not been changed yet:
75
- {unchanged_files}
76
-
77
- Below is the current file contents:
78
- {file_content}`,
79
- });
80
- //# sourceMappingURL=prompts.js.map
@@ -1 +0,0 @@
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,8 +0,0 @@
1
- export declare const getNextjsAppRouterDocs: ({ host, language, }: {
2
- host: string;
3
- language: "typescript" | "javascript";
4
- }) => string;
5
- export declare const getNextjsPagesRouterDocs: ({ host, language, }: {
6
- host: string;
7
- language: "typescript" | "javascript";
8
- }) => string;
@@ -1,257 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getNextjsPagesRouterDocs = exports.getNextjsAppRouterDocs = void 0;
4
- const urls_1 = require("../utils/urls");
5
- const getNextjsAppRouterDocs = ({ host, language, }) => {
6
- return `
7
- ==============================
8
- FILE: PostHogProvider.${language === 'typescript' ? 'tsx' : 'jsx'} (put it somewhere where client files are, like the components folder)
9
- LOCATION: Wherever other providers are, or the components folder
10
- ==============================
11
- Changes:
12
- - Create a PostHogProvider component that will be imported into the layout file.
13
-
14
- Example:
15
- --------------------------------------------------
16
- "use client"
17
-
18
- import posthog from "posthog-js"
19
- import { PostHogProvider as PHProvider, usePostHog } from "posthog-js/react"
20
- import { Suspense, useEffect } from "react"
21
- import { usePathname, useSearchParams } from "next/navigation"
22
-
23
- export function PostHogProvider({ children }: { children: React.ReactNode }) {
24
- useEffect(() => {
25
- posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
26
- api_host: "/ingest",
27
- ui_host: "${(0, urls_1.getUiHostFromHost)(host)}",
28
- capture_pageview: false, // We capture pageviews manually
29
- capture_pageleave: true, // Enable pageleave capture
30
- debug: process.env.NODE_ENV === "development",
31
- })
32
- }, [])
33
-
34
- return (
35
- <PHProvider client={posthog}>
36
- <SuspendedPostHogPageView />
37
- {children}
38
- </PHProvider>
39
- )
40
- }
41
-
42
-
43
- function PostHogPageView() {
44
- const pathname = usePathname()
45
- const searchParams = useSearchParams()
46
- const posthog = usePostHog()
47
-
48
- useEffect(() => {
49
- if (pathname && posthog) {
50
- let url = window.origin + pathname
51
- const search = searchParams.toString()
52
- if (search) {
53
- url += "?" + search
54
- }
55
- posthog.capture("$pageview", { "$current_url": url })
56
- }
57
- }, [pathname, searchParams, posthog])
58
-
59
- return null
60
- }
61
-
62
- function SuspendedPostHogPageView() {
63
- return (
64
- <Suspense fallback={null}>
65
- <PostHogPageView />
66
- </Suspense>
67
- )
68
- }
69
- --------------------------------------------------
70
-
71
- ==============================
72
- FILE: layout.${language === 'typescript' ? 'tsx' : 'jsx'}
73
- LOCATION: Wherever the root layout is
74
- ==============================
75
- Changes:
76
- - Import the PostHogProvider from the providers file and wrap the app in it.
77
-
78
- Example:
79
- --------------------------------------------------
80
- // other imports
81
- import { PostHogProvider } from "LOCATION_OF_POSTHOG_PROVIDER"
82
-
83
- export default function RootLayout({ children }) {
84
- return (
85
- <html lang="en">
86
- <body>
87
- <PostHogProvider>
88
- {/* other providers */}
89
- {children}
90
- {/* other providers */}
91
- </PostHogProvider>
92
- </body>
93
- </html>
94
- )
95
- }
96
- --------------------------------------------------
97
-
98
- ==============================
99
- FILE: posthog.${language === 'typescript' ? 'ts' : 'js'}
100
- LOCATION: Wherever works best given the project structure
101
- ==============================
102
- Changes:
103
- - Initialize the PostHog Node.js client
104
-
105
- Example:
106
- --------------------------------------------------
107
- import { PostHog } from "posthog-node"
108
-
109
- export default function PostHogClient() {
110
- const posthogClient = new PostHog(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
111
- host: "${host}",
112
- flushAt: 1,
113
- flushInterval: 0,
114
- })
115
- return posthogClient
116
- }
117
- --------------------------------------------------
118
-
119
- ==============================
120
- FILE: next.config.{js,ts,mjs,cjs}
121
- LOCATION: Wherever the root next config is
122
- ==============================
123
- Changes:
124
- - Add rewrites to the Next.js config to support PostHog, if there are existing rewrites, add the PostHog rewrites to them.
125
- - Add skipTrailingSlashRedirect to the Next.js config to support PostHog trailing slash API requests.
126
- - 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'.
127
-
128
- Example:
129
- --------------------------------------------------
130
- const nextConfig = {
131
- // other config
132
- async rewrites() {
133
- return [
134
- {
135
- source: "/ingest/static/:path*",
136
- destination: "${(0, urls_1.getAssetHostFromHost)(host)}/static/:path*",
137
- },
138
- {
139
- source: "/ingest/:path*",
140
- destination: "${host}/:path*",
141
- },
142
- {
143
- source: "/ingest/decide",
144
- destination: "${host}/decide",
145
- },
146
- ];
147
- },
148
- // This is required to support PostHog trailing slash API requests
149
- skipTrailingSlashRedirect: true,
150
- }
151
- module.exports = nextConfig
152
- --------------------------------------------------`;
153
- };
154
- exports.getNextjsAppRouterDocs = getNextjsAppRouterDocs;
155
- const getNextjsPagesRouterDocs = ({ host, language, }) => {
156
- return `
157
- ==============================
158
- FILE: _app.${language === 'typescript' ? 'tsx' : 'jsx'}
159
- LOCATION: Wherever the root _app.${language === 'typescript' ? 'tsx' : 'jsx'} file is
160
- ==============================
161
- Changes:
162
- - Initialize PostHog in _app.js.
163
- - Wrap the application in PostHogProvider.
164
- - Manually capture $pageview events.
165
-
166
- Example:
167
- --------------------------------------------------
168
- import { useEffect } from "react"
169
- import { Router } from "next/router"
170
- import posthog from "posthog-js"
171
- import { PostHogProvider } from "posthog-js/react"
172
-
173
- export default function App({ Component, pageProps }) {
174
- useEffect(() => {
175
- posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, {
176
- api_host: "/ingest",
177
- ui_host: "${(0, urls_1.getUiHostFromHost)(host)}",
178
- loaded: (posthog) => {
179
- if (process.env.NODE_ENV === "development") posthog.debug()
180
- },
181
- debug: process.env.NODE_ENV === "development",
182
- })
183
-
184
- const handleRouteChange = () => posthog?.capture("$pageview")
185
- Router.events.on("routeChangeComplete", handleRouteChange)
186
-
187
- return () => {
188
- Router.events.off("routeChangeComplete", handleRouteChange)
189
- }
190
- }, [])
191
-
192
- return (
193
- <PostHogProvider client={posthog}>
194
- <Component {...pageProps} />
195
- </PostHogProvider>
196
- )
197
- }
198
- --------------------------------------------------
199
-
200
- ==============================
201
- FILE: posthog.${language === 'typescript' ? 'ts' : 'js'}
202
- LOCATION: Wherever works best given the project structure
203
- ==============================
204
- Changes:
205
- - Initialize the PostHog Node.js client
206
-
207
- Example:
208
- --------------------------------------------------
209
- import { PostHog } from "posthog-node"
210
-
211
- export default function PostHogClient() {
212
- const posthogClient = new PostHog(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
213
- host: "${host}",
214
- flushAt: 1,
215
- flushInterval: 0,
216
- })
217
- return posthogClient
218
- }
219
- --------------------------------------------------
220
-
221
- ==============================
222
- FILE: next.config.{js,ts,mjs,cjs}
223
- LOCATION: Wherever the root next config is
224
- ==============================
225
- Changes:
226
- - Add rewrites to the Next.js config to support PostHog, if there are existing rewrites, add the PostHog rewrites to them.
227
- - Add skipTrailingSlashRedirect to the Next.js config to support PostHog trailing slash API requests.
228
- - 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'.
229
-
230
- Example:
231
- --------------------------------------------------
232
- const nextConfig = {
233
- // other config
234
- async rewrites() {
235
- return [
236
- {
237
- source: "/ingest/static/:path*",
238
- destination: "${(0, urls_1.getAssetHostFromHost)(host)}/static/:path*",
239
- },
240
- {
241
- source: "/ingest/:path*",
242
- destination: "${host}/:path*",
243
- },
244
- {
245
- source: "/ingest/decide",
246
- destination: "${host}/decide",
247
- },
248
- ];
249
- },
250
- // This is required to support PostHog trailing slash API requests
251
- skipTrailingSlashRedirect: true,
252
- }
253
- module.exports = nextConfig
254
- --------------------------------------------------`;
255
- };
256
- exports.getNextjsPagesRouterDocs = getNextjsPagesRouterDocs;
257
- //# sourceMappingURL=docs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"docs.js","sourceRoot":"","sources":["../../../src/nextjs/docs.ts"],"names":[],"mappings":";;;AAAA,wCAAwE;AAEjE,MAAM,sBAAsB,GAAG,CAAC,EACrC,IAAI,EACJ,QAAQ,GAIT,EAAE,EAAE;IACH,OAAO;;wBAGL,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KACtC;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;aAY1C,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;wBAyBO,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;;;;;;;;;;;;aAY1C,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;wBAyBO,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: \"${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: \"${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"]}