Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion e2e-tests/fixtures/18c11dda2ee4cd5c20c337d23dd61387.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"newContent": "import { StrictMode } from 'react'\nimport { createRoot } from 'react-dom/client'\nimport { PostHogProvider } from 'posthog-js/react'\nimport './index.css'\nimport App from './App.tsx'\n\ncreateRoot(document.getElementById('root')!).render(\n <StrictMode>\n <PostHogProvider\n apiKey={import.meta.env.VITE_PUBLIC_POSTHOG_KEY}\n options={{\n api_host: import.meta.env.VITE_PUBLIC_POSTHOG_HOST,\n defaults: '2025-05-24',\n capture_exceptions: true,\n debug: import.meta.env.MODE === 'development',\n }}\n >\n <App />\n </PostHogProvider>\n </StrictMode>,\n)\n"
"newContent": "import { StrictMode } from 'react'\nimport { createRoot } from 'react-dom/client'\nimport { PostHogProvider } from 'posthog-js/react'\nimport './index.css'\nimport App from './App.tsx'\n\ncreateRoot(document.getElementById('root')!).render(\n <StrictMode>\n <PostHogProvider\n apiKey={import.meta.env.VITE_PUBLIC_POSTHOG_PROJECT_TOKEN}\n options={{\n api_host: import.meta.env.VITE_PUBLIC_POSTHOG_HOST,\n defaults: '2025-05-24',\n capture_exceptions: true,\n debug: import.meta.env.MODE === 'development',\n }}\n >\n <App />\n </PostHogProvider>\n </StrictMode>,\n)\n"
}
2 changes: 1 addition & 1 deletion e2e-tests/fixtures/c9311503b2e7f6b9a027bd2402bb90b7.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"newContent": "import { PostHog } from \"posthog-node\";\n\n// NOTE: This is a Node.js client, so you can use it for sending events from the server side to PostHog.\nexport default function PostHogClient() {\n const posthogClient = new PostHog(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {\n host: process.env.NEXT_PUBLIC_POSTHOG_HOST,\n flushAt: 1,\n flushInterval: 0,\n });\n return posthogClient;\n}"
"newContent": "import { PostHog } from \"posthog-node\";\n\n// NOTE: This is a Node.js client, so you can use it for sending events from the server side to PostHog.\nexport default function PostHogClient() {\n const posthogClient = new PostHog(process.env.NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN!, {\n host: process.env.NEXT_PUBLIC_POSTHOG_HOST,\n flushAt: 1,\n flushInterval: 0,\n });\n return posthogClient;\n}"
}
2 changes: 1 addition & 1 deletion e2e-tests/fixtures/d4c43e8a5f058dd6547a2c74c6b6051f.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"newContent": "\"use client\"\n\nimport posthog from \"posthog-js\"\nimport { PostHogProvider as PHProvider } from \"posthog-js/react\"\nimport { useEffect } from \"react\"\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: \"http://localhost:8010\",\n defaults: '2025-05-24',\n capture_exceptions: true, // enables Error Tracking\n debug: process.env.NODE_ENV === \"development\",\n })\n }, [])\n\n return <PHProvider client={posthog}>{children}</PHProvider>\n}\n"
"newContent": "\"use client\"\n\nimport posthog from \"posthog-js\"\nimport { PostHogProvider as PHProvider } from \"posthog-js/react\"\nimport { useEffect } from \"react\"\n\nexport function PostHogProvider({ children }: { children: React.ReactNode }) {\n useEffect(() => {\n posthog.init(process.env.NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN!, {\n api_host: \"/ingest\",\n ui_host: \"http://localhost:8010\",\n defaults: '2025-05-24',\n capture_exceptions: true, // enables Error Tracking\n debug: process.env.NODE_ENV === \"development\",\n })\n }, [])\n\n return <PHProvider client={posthog}>{children}</PHProvider>\n}\n"
}
2 changes: 1 addition & 1 deletion src/frameworks/android/android-wizard-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const ANDROID_AGENT_CONFIG: FrameworkConfig<AndroidContext> = {
environment: {
uploadToHosting: false,
getEnvVars: (apiKey: string, host: string) => ({
POSTHOG_API_KEY: apiKey,
POSTHOG_PROJECT_TOKEN: apiKey,
POSTHOG_HOST: host,
}),
},
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/angular/angular-wizard-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const ANGULAR_AGENT_CONFIG: FrameworkConfig<AngularContext> = {
environment: {
uploadToHosting: false,
getEnvVars: (apiKey: string, host: string) => ({
NG_APP_POSTHOG_KEY: apiKey,
NG_APP_POSTHOG_PROJECT_TOKEN: apiKey,
NG_APP_POSTHOG_HOST: host,
}),
},
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/astro/astro-wizard-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const ASTRO_AGENT_CONFIG: FrameworkConfig<AstroContext> = {
environment: {
uploadToHosting: true,
getEnvVars: (apiKey: string, host: string) => ({
PUBLIC_POSTHOG_KEY: apiKey,
PUBLIC_POSTHOG_PROJECT_TOKEN: apiKey,
PUBLIC_POSTHOG_HOST: host,
}),
},
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/django/django-wizard-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export const DJANGO_AGENT_CONFIG: FrameworkConfig<DjangoContext> = {
environment: {
uploadToHosting: false,
getEnvVars: (apiKey: string, host: string) => ({
POSTHOG_API_KEY: apiKey,
POSTHOG_PROJECT_TOKEN: apiKey,
POSTHOG_HOST: host,
}),
},
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/fastapi/fastapi-wizard-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export const FASTAPI_AGENT_CONFIG: FrameworkConfig = {
environment: {
uploadToHosting: false,
getEnvVars: (apiKey: string, host: string) => ({
POSTHOG_API_KEY: apiKey,
POSTHOG_PROJECT_TOKEN: apiKey,
POSTHOG_HOST: host,
}),
},
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/flask/flask-wizard-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export const FLASK_AGENT_CONFIG: FrameworkConfig<FlaskContext> = {
environment: {
uploadToHosting: false,
getEnvVars: (apiKey: string, host: string) => ({
POSTHOG_API_KEY: apiKey,
POSTHOG_PROJECT_TOKEN: apiKey,
POSTHOG_HOST: host,
}),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const JAVASCRIPT_NODE_AGENT_CONFIG: FrameworkConfig<JavaScriptNodeContext
environment: {
uploadToHosting: false,
getEnvVars: (apiKey: string, host: string) => ({
POSTHOG_API_KEY: apiKey,
POSTHOG_PROJECT_TOKEN: apiKey,
POSTHOG_HOST: host,
}),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const JAVASCRIPT_WEB_AGENT_CONFIG: FrameworkConfig<JavaScriptContext> = {
environment: {
uploadToHosting: false,
getEnvVars: (apiKey: string, host: string) => ({
POSTHOG_API_KEY: apiKey,
POSTHOG_PROJECT_TOKEN: apiKey,
POSTHOG_HOST: host,
}),
},
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/laravel/laravel-wizard-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const LARAVEL_AGENT_CONFIG: FrameworkConfig<LaravelContext> = {
environment: {
uploadToHosting: false,
getEnvVars: (apiKey: string, host: string) => ({
POSTHOG_API_KEY: apiKey,
POSTHOG_PROJECT_TOKEN: apiKey,
POSTHOG_HOST: host,
}),
},
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/nextjs/nextjs-wizard-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const NEXTJS_AGENT_CONFIG: FrameworkConfig<NextjsContext> = {
environment: {
uploadToHosting: true,
getEnvVars: (apiKey: string, host: string) => ({
NEXT_PUBLIC_POSTHOG_KEY: apiKey,
NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN: apiKey,
NEXT_PUBLIC_POSTHOG_HOST: host,
}),
},
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/nuxt/nuxt-wizard-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const NUXT_AGENT_CONFIG: FrameworkConfig<NuxtContext> = {
environment: {
uploadToHosting: true,
getEnvVars: (apiKey: string, host: string) => ({
NUXT_PUBLIC_POSTHOG_KEY: apiKey,
NUXT_PUBLIC_POSTHOG_PROJECT_TOKEN: apiKey,
NUXT_PUBLIC_POSTHOG_HOST: host,
}),
},
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/python/python-wizard-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export const PYTHON_AGENT_CONFIG: FrameworkConfig<PythonContext> = {
environment: {
uploadToHosting: false,
getEnvVars: (apiKey: string, host: string) => ({
POSTHOG_API_KEY: apiKey,
POSTHOG_PROJECT_TOKEN: apiKey,
POSTHOG_HOST: host,
}),
},
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/rails/rails-wizard-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const RAILS_AGENT_CONFIG: FrameworkConfig<RailsContext> = {
environment: {
uploadToHosting: false,
getEnvVars: (apiKey: string, host: string) => ({
POSTHOG_API_KEY: apiKey,
POSTHOG_PROJECT_TOKEN: apiKey,
POSTHOG_HOST: host,
}),
},
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/react-native/react-native-wizard-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const REACT_NATIVE_AGENT_CONFIG: FrameworkConfig<ReactNativeContext> = {
environment: {
uploadToHosting: false,
getEnvVars: (apiKey: string, host: string) => ({
POSTHOG_API_KEY: apiKey,
POSTHOG_PROJECT_TOKEN: apiKey,
POSTHOG_HOST: host,
}),
},
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/react-router/react-router-wizard-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const REACT_ROUTER_AGENT_CONFIG: FrameworkConfig<ReactRouterContext> = {
environment: {
uploadToHosting: false,
getEnvVars: (apiKey: string, host: string) => ({
REACT_APP_POSTHOG_KEY: apiKey,
REACT_APP_POSTHOG_PROJECT_TOKEN: apiKey,
REACT_APP_POSTHOG_HOST: host,
}),
},
Expand Down
4 changes: 2 additions & 2 deletions src/frameworks/ruby/ruby-wizard-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const RUBY_AGENT_CONFIG: FrameworkConfig<RubyContext> = {
environment: {
uploadToHosting: false,
getEnvVars: (apiKey: string, host: string) => ({
POSTHOG_API_KEY: apiKey,
POSTHOG_PROJECT_TOKEN: apiKey,
POSTHOG_HOST: host,
}),
},
Expand Down Expand Up @@ -86,7 +86,7 @@ export const RUBY_AGENT_CONFIG: FrameworkConfig<RubyContext> = {
`Use PostHog::Client.new for scripts and standalone applications:`,
``,
`client = PostHog::Client.new(`,
` api_key: ENV['POSTHOG_API_KEY'],`,
` api_key: ENV['POSTHOG_PROJECT_TOKEN'],`,
` host: ENV['POSTHOG_HOST'] || 'https://us.i.posthog.com'`,
`)`,
``,
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/svelte/svelte-wizard-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const SVELTEKIT_AGENT_CONFIG: FrameworkConfig<SvelteKitContext> = {
environment: {
uploadToHosting: true,
getEnvVars: (apiKey: string, host: string) => ({
PUBLIC_POSTHOG_KEY: apiKey,
PUBLIC_POSTHOG_PROJECT_TOKEN: apiKey,
PUBLIC_POSTHOG_HOST: host,
}),
},
Expand Down
4 changes: 2 additions & 2 deletions src/frameworks/swift/swift-wizard-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const SWIFT_AGENT_CONFIG: FrameworkConfig<SwiftContext> = {
environment: {
uploadToHosting: false,
getEnvVars: (apiKey: string, host: string) => ({
POSTHOG_API_KEY: apiKey,
POSTHOG_PROJECT_TOKEN: apiKey,
POSTHOG_HOST: host,
}),
},
Expand Down Expand Up @@ -123,7 +123,7 @@ export const SWIFT_AGENT_CONFIG: FrameworkConfig<SwiftContext> = {
return changes;
},
getOutroNextSteps: () => [
'Set POSTHOG_API_KEY and POSTHOG_HOST in your Xcode scheme environment variables',
'Set POSTHOG_PROJECT_TOKEN and POSTHOG_HOST in your Xcode scheme environment variables',
'Build and run your app to see PostHog in action',
'Visit your PostHog dashboard to see incoming events',
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const TANSTACK_ROUTER_AGENT_CONFIG: FrameworkConfig<TanStackRouterContext
environment: {
uploadToHosting: false,
getEnvVars: (apiKey: string, host: string) => ({
VITE_PUBLIC_POSTHOG_KEY: apiKey,
VITE_PUBLIC_POSTHOG_PROJECT_TOKEN: apiKey,
VITE_PUBLIC_POSTHOG_HOST: host,
}),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const TANSTACK_START_AGENT_CONFIG: FrameworkConfig<TanStackStartContext>
environment: {
uploadToHosting: false,
getEnvVars: (apiKey: string, host: string) => ({
VITE_PUBLIC_POSTHOG_KEY: apiKey,
VITE_PUBLIC_POSTHOG_PROJECT_TOKEN: apiKey,
VITE_PUBLIC_POSTHOG_HOST: host,
}),
},
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/vue/vue-wizard-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const VUE_AGENT_CONFIG: FrameworkConfig<VueContext> = {
environment: {
uploadToHosting: true,
getEnvVars: (apiKey: string, host: string) => ({
VITE_POSTHOG_KEY: apiKey,
VITE_POSTHOG_PROJECT_TOKEN: apiKey,
VITE_POSTHOG_HOST: host,
}),
},
Expand Down
6 changes: 3 additions & 3 deletions src/lib/__tests__/yara-scanner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,14 @@ posthog.capture('signup', { email: user.email })`;
expect(result.matched).toBe(true);
});

it('detects POSTHOG_KEY assignment', () => {
const content = `POSTHOG_KEY = 'abcdefghijklmnopqrstuvwxyz1234'`;
it('detects POSTHOG_PROJECT_TOKEN assignment', () => {
const content = `POSTHOG_PROJECT_TOKEN = 'abcdefghijklmnopqrstuvwxyz1234'`;
const result = scan(content, 'PostToolUse', 'Write');
expect(result.matched).toBe(true);
});

it('does not trigger on env var reference', () => {
const content = `posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY)`;
const content = `posthog.init(process.env.NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN)`;
const result = scan(content, 'PostToolUse', 'Write');
expect(result.matched).toBe(false);
});
Expand Down
2 changes: 1 addition & 1 deletion src/lib/commandments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* without extra files, copying, or runtime I/O.
*/
const WIZARD_COMMANDMENTS = [
'Never hallucinate a PostHog API key, host, or any other secret. Always use the real values that have been configured for this project (for example via environment variables).',
'Never hallucinate a PostHog project token, host, or any other secret. Always use the real values that have been configured for this project (for example via environment variables).',

'Never write API keys, access tokens, or other secrets directly into source code. Always reference environment variables instead, and rely on the wizard-tools MCP server (check_env_keys / set_env_values) to create or update .env files.',

Expand Down
2 changes: 1 addition & 1 deletion src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const POSTHOG_US_CLIENT_ID = 'c4Rdw8DIxgtQfA80IiSnGKlNX8QN00cFWF00QQhM';
export const POSTHOG_EU_CLIENT_ID = 'bx2C5sZRN03TkdjraCcetvQFPGH6N2Y9vRLkcKEy';
export const POSTHOG_DEV_CLIENT_ID = 'DC5uRLVbGI02YQ82grxgnK6Qn12SXWpCqdPb60oZ';
export const POSTHOG_PROXY_CLIENT_ID = POSTHOG_US_CLIENT_ID;
export const DUMMY_PROJECT_API_KEY = '_YOUR_POSTHOG_PROJECT_API_KEY_';
export const DUMMY_PROJECT_API_KEY = '_YOUR_POSTHOG_PROJECT_TOKEN_';

// ── Wizard run / variants ───────────────────────────────────────────

Expand Down
6 changes: 3 additions & 3 deletions src/lib/wizard-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,16 +295,16 @@ export async function createWizardToolsServer(options: WizardToolsOptions) {
.describe('Key-value pairs to set'),
},
(args: { filePath: string; values: Record<string, string> }) => {
// Block the wrong key name — the correct key is NEXT_PUBLIC_POSTHOG_KEY or similar
// Block the wrong key name — the correct key is NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN or similar
const forbidden = Object.keys(args.values).find(
(k) => k.toUpperCase() === 'POSTHOG_API_KEY',
(k) => k.toUpperCase() === 'POSTHOG_KEY',
);
if (forbidden) {
return {
content: [
{
type: 'text' as const,
text: `Error: "${forbidden}" is not a valid PostHog env var name. Use the project-specific key name from your framework's integration guide (e.g. NEXT_PUBLIC_POSTHOG_KEY).`,
text: `Error: "${forbidden}" is not a valid PostHog env var name. Use the project-specific key name from your framework's integration guide (e.g. NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN).`,
},
],
isError: true,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/yara-scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const hardcoded_posthog_key: YaraRule = {
// Hardcoded key assignment patterns
/apiKey\s*[:=]\s*['"][a-zA-Z0-9_]{20,}['"]/,
/api_key\s*[:=]\s*['"][a-zA-Z0-9_]{20,}['"]/,
/POSTHOG_KEY\s*[:=]\s*['"][a-zA-Z0-9_]{20,}['"]/,
/POSTHOG_PROJECT_TOKEN\s*[:=]\s*['"][a-zA-Z0-9_]{20,}['"]/,
],
};

Expand Down
4 changes: 2 additions & 2 deletions src/utils/rules/astro-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ PostHog is already integrated into this Astro project. The configuration include

- PostHog initialization in `src/components/posthog.astro`
- Layout setup in `src/layouts/PostHogLayout.astro`
- Environment variables for API key and host
- Environment variables for project token and host

## Key Guidelines

Expand All @@ -17,7 +17,7 @@ PostHog is already integrated into this Astro project. The configuration include

### Environment Variables
- Use `PUBLIC_` prefix for client-side environment variables in Astro
- `PUBLIC_POSTHOG_KEY` - Your PostHog project API key
- `PUBLIC_POSTHOG_PROJECT_TOKEN` - Your PostHog project token
- `PUBLIC_POSTHOG_HOST` - Your PostHog instance URL

### Best Practices
Expand Down
Loading