@posthog/wizard 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +47 -0
- package/README.md +34 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +28 -0
- package/dist/bin.js.map +1 -0
- package/dist/src/lib/constants.d.ts +20 -0
- package/dist/src/lib/constants.js +34 -0
- package/dist/src/lib/constants.js.map +1 -0
- package/dist/src/nextjs/docs.d.ts +8 -0
- package/dist/src/nextjs/docs.js +235 -0
- package/dist/src/nextjs/docs.js.map +1 -0
- package/dist/src/nextjs/nextjs-wizard.d.ts +9 -0
- package/dist/src/nextjs/nextjs-wizard.js +331 -0
- package/dist/src/nextjs/nextjs-wizard.js.map +1 -0
- package/dist/src/nextjs/prompts.d.ts +12 -0
- package/dist/src/nextjs/prompts.js +64 -0
- package/dist/src/nextjs/prompts.js.map +1 -0
- package/dist/src/nextjs/utils.d.ts +9 -0
- package/dist/src/nextjs/utils.js +80 -0
- package/dist/src/nextjs/utils.js.map +1 -0
- package/dist/src/run.d.ts +8 -0
- package/dist/src/run.js +69 -0
- package/dist/src/run.js.map +1 -0
- package/dist/src/telemetry.d.ts +2 -0
- package/dist/src/telemetry.js +13 -0
- package/dist/src/telemetry.js.map +1 -0
- package/dist/src/utils/analytics.d.ts +4 -0
- package/dist/src/utils/analytics.js +10 -0
- package/dist/src/utils/analytics.js.map +1 -0
- package/dist/src/utils/bash.d.ts +2 -0
- package/dist/src/utils/bash.js +54 -0
- package/dist/src/utils/bash.js.map +1 -0
- package/dist/src/utils/clack-utils.d.ts +177 -0
- package/dist/src/utils/clack-utils.js +628 -0
- package/dist/src/utils/clack-utils.js.map +1 -0
- package/dist/src/utils/clack.d.ts +2 -0
- package/dist/src/utils/clack.js +9 -0
- package/dist/src/utils/clack.js.map +1 -0
- package/dist/src/utils/debug.d.ts +2 -0
- package/dist/src/utils/debug.js +22 -0
- package/dist/src/utils/debug.js.map +1 -0
- package/dist/src/utils/environment.d.ts +1 -0
- package/dist/src/utils/environment.js +12 -0
- package/dist/src/utils/environment.js.map +1 -0
- package/dist/src/utils/file-utils.d.ts +2 -0
- package/dist/src/utils/file-utils.js +38 -0
- package/dist/src/utils/file-utils.js.map +1 -0
- package/dist/src/utils/logging.d.ts +9 -0
- package/dist/src/utils/logging.js +50 -0
- package/dist/src/utils/logging.js.map +1 -0
- package/dist/src/utils/package-json.d.ts +25 -0
- package/dist/src/utils/package-json.js +27 -0
- package/dist/src/utils/package-json.js.map +1 -0
- package/dist/src/utils/package-manager.d.ts +19 -0
- package/dist/src/utils/package-manager.js +188 -0
- package/dist/src/utils/package-manager.js.map +1 -0
- package/dist/src/utils/query.d.ts +6 -0
- package/dist/src/utils/query.js +27 -0
- package/dist/src/utils/query.js.map +1 -0
- package/dist/src/utils/semver.d.ts +5 -0
- package/dist/src/utils/semver.js +25 -0
- package/dist/src/utils/semver.js.map +1 -0
- package/dist/src/utils/string.d.ts +1 -0
- package/dist/src/utils/string.js +9 -0
- package/dist/src/utils/string.js.map +1 -0
- package/dist/src/utils/types.d.ts +30 -0
- package/dist/src/utils/types.js +3 -0
- package/dist/src/utils/types.js.map +1 -0
- package/dist/src/utils/vendor/is-unicorn-supported.d.ts +1 -0
- package/dist/src/utils/vendor/is-unicorn-supported.js +24 -0
- package/dist/src/utils/vendor/is-unicorn-supported.js.map +1 -0
- package/package.json +135 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 PostHog
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
--------------------------------------------------------------------------------
|
|
24
|
+
|
|
25
|
+
Portions of this software are derived from Sentry’s codebase located at https://github.com/getsentry/sentry-wizard and are used under the terms of the MIT License provided below:
|
|
26
|
+
|
|
27
|
+
The MIT License (MIT)
|
|
28
|
+
|
|
29
|
+
Copyright (c) 2017 Sentry
|
|
30
|
+
|
|
31
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
32
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
33
|
+
in the Software without restriction, including without limitation the rights
|
|
34
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
35
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
36
|
+
furnished to do so, subject to the following conditions:
|
|
37
|
+
|
|
38
|
+
The above copyright notice and this permission notice shall be included in all
|
|
39
|
+
copies or substantial portions of the Software.
|
|
40
|
+
|
|
41
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
42
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
43
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
44
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
45
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
46
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
47
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
|
|
2
|
+
<p align="center">
|
|
3
|
+
<img alt="posthoglogo" src="https://user-images.githubusercontent.com/65415371/205059737-c8a4f836-4889-4654-902e-f302b187b6a0.png">
|
|
4
|
+
</p>
|
|
5
|
+
|
|
6
|
+
> **⚠️ Experimental:** This wizard is still in an experimental phase.
|
|
7
|
+
> If you have any feedback, please drop an email to **joshua** [at] **posthog** [dot] **com**.
|
|
8
|
+
|
|
9
|
+
<h1>PostHog Wizard</h1>
|
|
10
|
+
<h4>The PostHog Wizard helps you quickly add PostHog to your project.</h4>
|
|
11
|
+
|
|
12
|
+
# Usage
|
|
13
|
+
|
|
14
|
+
To use the wizard, you can run it directly using:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npx @posthog/wizard
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Currently the wizard can be used for Next.js only. If you have other platforms you would like the wizard to support, please open a [GitHub issue](https://github.com/posthog/wizard/issues)!
|
|
21
|
+
|
|
22
|
+
# Options
|
|
23
|
+
|
|
24
|
+
The following CLI arguments are available:
|
|
25
|
+
|
|
26
|
+
| Option | Description | Type | Default | Choices | Environment Variable |
|
|
27
|
+
| ----------------- | ----------------------------------------------------- | ------- | ------------------------------- | -------- | ---------------------------- |
|
|
28
|
+
| `--help` | Show help | boolean | | | |
|
|
29
|
+
| `--version` | Show version number | boolean | | | |
|
|
30
|
+
| `--debug` | Enable verbose logging | boolean | `false` | | `POSTHOG_WIZARD_DEBUG` |
|
|
31
|
+
| `--integration` | Choose the integration to setup | choices | Select integration during setup | "nextjs" | `POSTHOG_WIZARD_INTEGRATION` |
|
|
32
|
+
| `--force-install` | Force install the SDK NPM package (use with caution!) | boolean | `false` | | |
|
|
33
|
+
|
|
34
|
+
> 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) 💖
|
package/dist/bin.d.ts
ADDED
package/dist/bin.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
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
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../bin.ts"],"names":[],"mappings":";;;;;;AACA,mCAAmC;AACnC,iDAA0C;AAE1C,kDAA0B;AAC1B,2CAAwC;AAExC,MAAM,kBAAkB,GAAG,WAAW,CAAC;AAEvC,iFAAiF;AACjF,+BAA+B;AAC/B,IAAI,CAAC,IAAA,kBAAS,EAAC,OAAO,CAAC,OAAO,EAAE,kBAAkB,CAAC,EAAE,CAAC;IACpD,IAAA,aAAG,EACD,mCAAmC,kBAAkB,2BAA2B,OAAO,CAAC,OAAO,wCAAwC,CACxI,CAAC;IACF,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"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare enum Integration {
|
|
2
|
+
nextjs = "nextjs"
|
|
3
|
+
}
|
|
4
|
+
export declare function getIntegrationDescription(type: string): string;
|
|
5
|
+
type IntegrationChoice = {
|
|
6
|
+
name: string;
|
|
7
|
+
value: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function getIntegrationChoices(): IntegrationChoice[];
|
|
10
|
+
export interface Args {
|
|
11
|
+
debug: boolean;
|
|
12
|
+
integration: Integration;
|
|
13
|
+
}
|
|
14
|
+
export declare const DEFAULT_URL = "http://us.posthog.com";
|
|
15
|
+
export declare const ISSUES_URL = "https://github.com/posthog/wizard/issues";
|
|
16
|
+
export declare const INSTALL_DIR: string;
|
|
17
|
+
export declare const CLOUD_URL = "https://us.posthog.com";
|
|
18
|
+
export declare const DEFAULT_HOST_URL = "https://us.i.posthog.com";
|
|
19
|
+
export declare const DUMMY_PROJECT_API_KEY = "_YOUR_POSTHOG_PROJECT_API_KEY_";
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
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.DUMMY_PROJECT_API_KEY = exports.DEFAULT_HOST_URL = exports.CLOUD_URL = exports.INSTALL_DIR = exports.ISSUES_URL = exports.DEFAULT_URL = exports.Integration = void 0;
|
|
7
|
+
exports.getIntegrationDescription = getIntegrationDescription;
|
|
8
|
+
exports.getIntegrationChoices = getIntegrationChoices;
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
var Integration;
|
|
11
|
+
(function (Integration) {
|
|
12
|
+
Integration["nextjs"] = "nextjs";
|
|
13
|
+
})(Integration || (exports.Integration = Integration = {}));
|
|
14
|
+
function getIntegrationDescription(type) {
|
|
15
|
+
switch (type) {
|
|
16
|
+
case Integration.nextjs:
|
|
17
|
+
return 'Next.js';
|
|
18
|
+
default:
|
|
19
|
+
throw new Error(`Unknown integration ${type}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function getIntegrationChoices() {
|
|
23
|
+
return Object.keys(Integration).map((type) => ({
|
|
24
|
+
name: getIntegrationDescription(type),
|
|
25
|
+
value: type,
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
exports.DEFAULT_URL = 'http://us.posthog.com';
|
|
29
|
+
exports.ISSUES_URL = 'https://github.com/posthog/wizard/issues';
|
|
30
|
+
exports.INSTALL_DIR = path_1.default.join(process.cwd(), process.env.POSTHOG_WIZARD_INSTALL_DIR ?? '');
|
|
31
|
+
exports.CLOUD_URL = 'https://us.posthog.com';
|
|
32
|
+
exports.DEFAULT_HOST_URL = 'https://us.i.posthog.com';
|
|
33
|
+
exports.DUMMY_PROJECT_API_KEY = '_YOUR_POSTHOG_PROJECT_API_KEY_';
|
|
34
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/lib/constants.ts"],"names":[],"mappings":";;;;;;AAMA,8DAOC;AAOD,sDAKC;AAzBD,gDAAwB;AAExB,IAAY,WAEX;AAFD,WAAY,WAAW;IACrB,gCAAiB,CAAA;AACnB,CAAC,EAFW,WAAW,2BAAX,WAAW,QAEtB;AAED,SAAgB,yBAAyB,CAAC,IAAY;IACpD,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,WAAW,CAAC,MAAM;YACrB,OAAO,SAAS,CAAC;QACnB;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,WAAW,GAAG,uBAAuB,CAAC;AACtC,QAAA,UAAU,GAAG,0CAA0C,CAAC;AACxD,QAAA,WAAW,GAAG,cAAI,CAAC,IAAI,CAClC,OAAO,CAAC,GAAG,EAAE,EACb,OAAO,CAAC,GAAG,CAAC,0BAA0B,IAAI,EAAE,CAC7C,CAAC;AACW,QAAA,SAAS,GAAG,wBAAwB,CAAC;AACrC,QAAA,gBAAgB,GAAG,0BAA0B,CAAC;AAC9C,QAAA,qBAAqB,GAAG,gCAAgC,CAAC","sourcesContent":["import path from 'path';\n\nexport enum Integration {\n nextjs = 'nextjs',\n}\n\nexport function getIntegrationDescription(type: string): string {\n switch (type) {\n case Integration.nextjs:\n return 'Next.js';\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 DEFAULT_URL = 'http://us.posthog.com';\nexport const ISSUES_URL = 'https://github.com/posthog/wizard/issues';\nexport const INSTALL_DIR = path.join(\n process.cwd(),\n process.env.POSTHOG_WIZARD_INSTALL_DIR ?? '',\n);\nexport const CLOUD_URL = 'https://us.posthog.com';\nexport const DEFAULT_HOST_URL = 'https://us.i.posthog.com';\nexport const DUMMY_PROJECT_API_KEY = '_YOUR_POSTHOG_PROJECT_API_KEY_';\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
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;
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getNextjsPagesRouterDocs = exports.getNextjsAppRouterDocs = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
const getNextjsAppRouterDocs = ({ host, language, }) => {
|
|
6
|
+
return `
|
|
7
|
+
==============================
|
|
8
|
+
FILE: app/components/PostHogProvider.${language === 'typescript' ? 'tsx' : 'jsx'}
|
|
9
|
+
==============================
|
|
10
|
+
Changes:
|
|
11
|
+
- Create a PostHogProvider component that will be imported into the layout file.
|
|
12
|
+
|
|
13
|
+
Example:
|
|
14
|
+
--------------------------------------------------
|
|
15
|
+
'use client'
|
|
16
|
+
|
|
17
|
+
import posthog from 'posthog-js'
|
|
18
|
+
import { PostHogProvider as PHProvider, usePostHog } from 'posthog-js/react'
|
|
19
|
+
import { Suspense, useEffect } from 'react'
|
|
20
|
+
import { usePathname, useSearchParams } from "next/navigation"
|
|
21
|
+
|
|
22
|
+
export function PostHogProvider({ children }: { children: React.ReactNode }) {
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
|
|
25
|
+
api_host: "/ingest",
|
|
26
|
+
ui_host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
|
|
27
|
+
capture_pageview: false, // We capture pageviews manually
|
|
28
|
+
capture_pageleave: true, // Enable pageleave capture
|
|
29
|
+
})
|
|
30
|
+
}, [])
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<PHProvider client={posthog}>
|
|
34
|
+
<SuspendedPostHogPageView />
|
|
35
|
+
{children}
|
|
36
|
+
</PHProvider>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
function PostHogPageView() {
|
|
42
|
+
const pathname = usePathname()
|
|
43
|
+
const searchParams = useSearchParams()
|
|
44
|
+
const posthog = usePostHog()
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (pathname && posthog) {
|
|
48
|
+
let url = window.origin + pathname
|
|
49
|
+
const search = searchParams.toString()
|
|
50
|
+
if (search) {
|
|
51
|
+
url += "?" + search
|
|
52
|
+
}
|
|
53
|
+
posthog.capture('$pageview', { '$current_url': url })
|
|
54
|
+
}
|
|
55
|
+
}, [pathname, searchParams, posthog])
|
|
56
|
+
|
|
57
|
+
return null
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function SuspendedPostHogPageView() {
|
|
61
|
+
return (
|
|
62
|
+
<Suspense fallback={null}>
|
|
63
|
+
<PostHogPageView />
|
|
64
|
+
</Suspense>
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
--------------------------------------------------
|
|
68
|
+
|
|
69
|
+
==============================
|
|
70
|
+
FILE: app/layout.${language === 'typescript' ? 'tsx' : 'jsx'}
|
|
71
|
+
==============================
|
|
72
|
+
Changes:
|
|
73
|
+
- Import the PostHogProvider from the providers file and wrap the app in it.
|
|
74
|
+
|
|
75
|
+
Example:
|
|
76
|
+
--------------------------------------------------
|
|
77
|
+
// other imports
|
|
78
|
+
import { PostHogProvider } from './components/providers'
|
|
79
|
+
|
|
80
|
+
export default function RootLayout({ children }) {
|
|
81
|
+
return (
|
|
82
|
+
<html lang="en">
|
|
83
|
+
<body>
|
|
84
|
+
<PostHogProvider>
|
|
85
|
+
{/* other providers */}
|
|
86
|
+
{children}
|
|
87
|
+
{/* other providers */}
|
|
88
|
+
</PostHogProvider>
|
|
89
|
+
</body>
|
|
90
|
+
</html>
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
--------------------------------------------------
|
|
94
|
+
|
|
95
|
+
==============================
|
|
96
|
+
FILE: app/lib/server/posthog.${language === 'typescript' ? 'ts' : 'js'}
|
|
97
|
+
==============================
|
|
98
|
+
Changes:
|
|
99
|
+
- Initialize the PostHog Node.js client
|
|
100
|
+
|
|
101
|
+
Example:
|
|
102
|
+
--------------------------------------------------
|
|
103
|
+
import { PostHog } from 'posthog-node'
|
|
104
|
+
|
|
105
|
+
export default function PostHogClient() {
|
|
106
|
+
const posthogClient = new PostHog(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
|
|
107
|
+
host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
|
|
108
|
+
flushAt: 1,
|
|
109
|
+
flushInterval: 0,
|
|
110
|
+
})
|
|
111
|
+
return posthogClient
|
|
112
|
+
}
|
|
113
|
+
--------------------------------------------------
|
|
114
|
+
|
|
115
|
+
==============================
|
|
116
|
+
FILE: next.config.{js,ts,mjs,cjs}
|
|
117
|
+
==============================
|
|
118
|
+
Changes:
|
|
119
|
+
- Add rewrites to the Next.js config to support PostHog, if there are existing rewrites, add the PostHog rewrites to them.
|
|
120
|
+
- Add skipTrailingSlashRedirect to the Next.js config to support PostHog trailing slash API requests.
|
|
121
|
+
- This can be of type js, ts, mjs, cjs etc. You should adapt the file according
|
|
122
|
+
Example:
|
|
123
|
+
--------------------------------------------------
|
|
124
|
+
const nextConfig = {
|
|
125
|
+
// other config
|
|
126
|
+
async rewrites() {
|
|
127
|
+
return [
|
|
128
|
+
{
|
|
129
|
+
source: "/ingest/static/:path*",
|
|
130
|
+
destination: "${(0, utils_1.getAssetHostFromHost)(host)}/static/:path*",
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
source: "/ingest/:path*",
|
|
134
|
+
destination: "${host}/:path*",
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
source: "/ingest/decide",
|
|
138
|
+
destination: "${host}/decide",
|
|
139
|
+
},
|
|
140
|
+
];
|
|
141
|
+
},
|
|
142
|
+
// This is required to support PostHog trailing slash API requests
|
|
143
|
+
skipTrailingSlashRedirect: true,
|
|
144
|
+
}
|
|
145
|
+
module.exports = nextConfig
|
|
146
|
+
--------------------------------------------------`;
|
|
147
|
+
};
|
|
148
|
+
exports.getNextjsAppRouterDocs = getNextjsAppRouterDocs;
|
|
149
|
+
const getNextjsPagesRouterDocs = ({ host, language, }) => {
|
|
150
|
+
return `
|
|
151
|
+
==============================
|
|
152
|
+
FILE: pages/_app.${language === 'typescript' ? 'tsx' : 'jsx'}
|
|
153
|
+
==============================
|
|
154
|
+
Changes:
|
|
155
|
+
- Initialize PostHog in _app.js.
|
|
156
|
+
- Wrap the application in PostHogProvider.
|
|
157
|
+
- Manually capture $pageview events.
|
|
158
|
+
|
|
159
|
+
Example:
|
|
160
|
+
--------------------------------------------------
|
|
161
|
+
import { useEffect } from 'react'
|
|
162
|
+
import { Router } from 'next/router'
|
|
163
|
+
import posthog from 'posthog-js'
|
|
164
|
+
import { PostHogProvider } from 'posthog-js/react'
|
|
165
|
+
|
|
166
|
+
export default function App({ Component, pageProps }) {
|
|
167
|
+
useEffect(() => {
|
|
168
|
+
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, {
|
|
169
|
+
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST || 'https://us.i.posthog.com',
|
|
170
|
+
loaded: (posthog) => {
|
|
171
|
+
if (process.env.NODE_ENV === 'development') posthog.debug()
|
|
172
|
+
},
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
const handleRouteChange = () => posthog?.capture('$pageview')
|
|
176
|
+
Router.events.on('routeChangeComplete', handleRouteChange)
|
|
177
|
+
|
|
178
|
+
return () => {
|
|
179
|
+
Router.events.off('routeChangeComplete', handleRouteChange)
|
|
180
|
+
}
|
|
181
|
+
}, [])
|
|
182
|
+
|
|
183
|
+
return (
|
|
184
|
+
<PostHogProvider client={posthog}>
|
|
185
|
+
<Component {...pageProps} />
|
|
186
|
+
</PostHogProvider>
|
|
187
|
+
)
|
|
188
|
+
}
|
|
189
|
+
--------------------------------------------------
|
|
190
|
+
|
|
191
|
+
==============================
|
|
192
|
+
FILE: lib/server/posthog.${language === 'typescript' ? 'ts' : 'js'}
|
|
193
|
+
==============================
|
|
194
|
+
Changes:
|
|
195
|
+
- Initialize the PostHog Node.js client for server-side tracking.
|
|
196
|
+
|
|
197
|
+
Example:
|
|
198
|
+
--------------------------------------------------
|
|
199
|
+
import { PostHog } from 'posthog-node'
|
|
200
|
+
|
|
201
|
+
export default function PostHogClient() {
|
|
202
|
+
return new PostHog(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
|
|
203
|
+
host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
|
|
204
|
+
flushAt: 1,
|
|
205
|
+
flushInterval: 0,
|
|
206
|
+
})
|
|
207
|
+
}
|
|
208
|
+
--------------------------------------------------
|
|
209
|
+
|
|
210
|
+
==============================
|
|
211
|
+
FILE: next.config.{js,ts,mjs,cjs}
|
|
212
|
+
==============================
|
|
213
|
+
Changes:
|
|
214
|
+
- Add rewrites to support PostHog tracking.
|
|
215
|
+
- Enable support for PostHog API trailing slash requests.
|
|
216
|
+
|
|
217
|
+
Example:
|
|
218
|
+
--------------------------------------------------
|
|
219
|
+
const nextConfig = {
|
|
220
|
+
async rewrites() {
|
|
221
|
+
return [
|
|
222
|
+
{ source: "/ingest/static/:path*", destination: "${(0, utils_1.getAssetHostFromHost)(host)}/static/:path*" },
|
|
223
|
+
{ source: "/ingest/:path*", destination: "${host}/:path*" },
|
|
224
|
+
{ source: "/ingest/decide", destination: "${host}/decide" },
|
|
225
|
+
]
|
|
226
|
+
},
|
|
227
|
+
skipTrailingSlashRedirect: true,
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
module.exports = nextConfig
|
|
231
|
+
--------------------------------------------------
|
|
232
|
+
`;
|
|
233
|
+
};
|
|
234
|
+
exports.getNextjsPagesRouterDocs = getNextjsPagesRouterDocs;
|
|
235
|
+
//# sourceMappingURL=docs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docs.js","sourceRoot":"","sources":["../../../src/nextjs/docs.ts"],"names":[],"mappings":";;;AAAA,mCAA+C;AAExC,MAAM,sBAAsB,GAAG,CAAC,EACrC,IAAI,EACJ,QAAQ,GAIT,EAAE,EAAE;IACH,OAAO;;uCAE8B,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KACvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBA8De,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;+BA0B7B,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAkC9C,IAAA,4BAAoB,EAAC,IAAI,CAAC;;;;wBAI1B,IAAI;;;;wBAIJ,IAAI;;;;;;;;mDAQuB,CAAC;AACpD,CAAC,CAAC;AArJW,QAAA,sBAAsB,0BAqJjC;AAEK,MAAM,wBAAwB,GAAG,CAAC,EACvC,IAAI,EACJ,QAAQ,GAIT,EAAE,EAAE;IACH,OAAO;;mBAEU,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BAwCjC,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yDA8BT,IAAA,4BAAoB,EACzE,IAAI,CACL;kDAC+C,IAAI;kDACJ,IAAI;;;;;;;;CAQrD,CAAC;AACF,CAAC,CAAC;AA5FW,QAAA,wBAAwB,4BA4FnC","sourcesContent":["import { getAssetHostFromHost } from './utils';\n\nexport const getNextjsAppRouterDocs = ({\n host,\n language,\n}: {\n host: string;\n language: 'typescript' | 'javascript';\n}) => {\n return `\n==============================\nFILE: app/components/PostHogProvider.${language === 'typescript' ? 'tsx' : 'jsx'\n }\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: process.env.NEXT_PUBLIC_POSTHOG_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: app/layout.${language === 'typescript' ? 'tsx' : 'jsx'}\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 './components/providers'\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: app/lib/server/posthog.${language === 'typescript' ? 'ts' : 'js'}\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}\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\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: pages/_app.${language === 'typescript' ? 'tsx' : 'jsx'}\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: process.env.NEXT_PUBLIC_POSTHOG_HOST || 'https://us.i.posthog.com',\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: lib/server/posthog.${language === 'typescript' ? 'ts' : 'js'}\n==============================\nChanges:\n- Initialize the PostHog Node.js client for server-side tracking.\n\nExample:\n--------------------------------------------------\nimport { PostHog } from 'posthog-node'\n\nexport default function PostHogClient() {\n return new PostHog(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {\n host: process.env.NEXT_PUBLIC_POSTHOG_HOST,\n flushAt: 1,\n flushInterval: 0,\n })\n}\n--------------------------------------------------\n\n==============================\nFILE: next.config.{js,ts,mjs,cjs}\n==============================\nChanges:\n- Add rewrites to support PostHog tracking.\n- Enable support for PostHog API trailing slash requests.\n\nExample:\n--------------------------------------------------\nconst nextConfig = {\n async rewrites() {\n return [\n { source: \"/ingest/static/:path*\", destination: \"${getAssetHostFromHost(\n host,\n )}/static/:path*\" },\n { source: \"/ingest/:path*\", destination: \"${host}/:path*\" },\n { source: \"/ingest/decide\", destination: \"${host}/decide\" },\n ]\n },\n skipTrailingSlashRedirect: true,\n}\n\nmodule.exports = nextConfig\n--------------------------------------------------\n`;\n};\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { WizardOptions } from '../utils/types';
|
|
2
|
+
import { Integration } from '../lib/constants';
|
|
3
|
+
export declare function runNextjsWizard(options: WizardOptions): Promise<void>;
|
|
4
|
+
export declare function detectNextJs(): Promise<Integration.nextjs | undefined>;
|
|
5
|
+
export declare function addOrUpdateEnvironmentVariables({ projectApiKey, host, }: {
|
|
6
|
+
projectApiKey: string;
|
|
7
|
+
host: string;
|
|
8
|
+
}): Promise<void>;
|
|
9
|
+
export declare function getDotGitignore(): string | undefined;
|