Skip to content

Commit a86c857

Browse files
authored
Merge pull request #208 from PostHog/posthog-code/project-token-terminology
Use "project API token" terminology over "API key"
2 parents 8692b9f + c8e475a commit a86c857

17 files changed

Lines changed: 40 additions & 40 deletions

File tree

context/commandments.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ commandments:
170170
- "capture_exception takes POSITIONAL args: PostHog.capture_exception(exception, distinct_id, additional_properties) — do NOT use keyword args"
171171
- "Define posthog_distinct_id on the User model for automatic user association in error reports — posthog-rails auto-detects by trying: posthog_distinct_id, distinct_id, id, pk, uuid (in order)"
172172
- "For ActiveJob user association, use the class-level DSL `posthog_distinct_id ->(user) { user.email }` or pass user_id: in a hash argument"
173-
- Store API key in Rails credentials or environment variables, never hardcode
173+
- Store the project token in Rails credentials or environment variables, never hardcode
174174
- "For frontend tracking alongside posthog-rails, add the posthog-js snippet to the layout template — posthog-js handles pageviews, session replay, and client-side errors while posthog-ruby handles backend events, server errors, feature flags, and background jobs"
175175

176176
hogql:

context/skills/creating-product-tours/description.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Product tours use PostHog feature flags for targeting (who sees the tour and when) and PostHog events for tracking (completion, drop-off, step funnel). UI components should be custom-built but reusable across multiple tours.
44

5-
**Local-dev behavior**: the tour renders locally even when PostHog isn't initialized (no API key, provider not mounted, ad blocker active). The feature flag infrastructure is still scaffolded for production rollout — it just isn't a hard gate in dev. This lets engineers iterate on the tour without needing a PostHog project wired up. See "Local development" below for how the fail-open works and how to opt out.
5+
**Local-dev behavior**: the tour renders locally even when PostHog isn't initialized (no project token, provider not mounted, ad blocker active). The feature flag infrastructure is still scaffolded for production rollout — it just isn't a hard gate in dev. This lets engineers iterate on the tour without needing a PostHog project wired up. See "Local development" below for how the fail-open works and how to opt out.
66

77
## Step 1: gather requirements
88

@@ -73,7 +73,7 @@ interface UseTourOptions {
7373
storageKey?: string; // localStorage key to remember completion; defaults to `tour-${flagKey}`
7474
// When true, the flag check is enforced even if PostHog isn't initialized
7575
// (the tour won't render locally without PostHog wired up). Default false:
76-
// fail-open in dev so engineers can iterate without an API key.
76+
// fail-open in dev so engineers can iterate without a project token.
7777
requireFlag?: boolean;
7878
}
7979

context/skills/mcp-analytics/description.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Create the PostHog client **once at module scope** (never per request), reading
8282
```ts
8383
import { PostHog } from "posthog-node"
8484

85-
const posthog = new PostHog(process.env.POSTHOG_PROJECT_API_KEY, {
85+
const posthog = new PostHog(process.env.POSTHOG_PROJECT_TOKEN, {
8686
host: process.env.POSTHOG_HOST, // https://us.i.posthog.com or https://eu.i.posthog.com
8787
})
8888
```
@@ -115,7 +115,7 @@ const handler = createMcpHandler((server) => {
115115
```ts
116116
import { PostHogMCP } from "@posthog/mcp"
117117

118-
const posthog = new PostHogMCP(process.env.POSTHOG_PROJECT_API_KEY, {
118+
const posthog = new PostHogMCP(process.env.POSTHOG_PROJECT_TOKEN, {
119119
host: process.env.POSTHOG_HOST,
120120
})
121121

@@ -145,7 +145,7 @@ import { Module } from "@nestjs/common"
145145
import { McpModule } from "@rekog/mcp-nest"
146146
import { PostHog, instrumentMutator } from "@posthog/mcp"
147147

148-
const posthog = new PostHog(process.env.POSTHOG_PROJECT_API_KEY, {
148+
const posthog = new PostHog(process.env.POSTHOG_PROJECT_TOKEN, {
149149
host: process.env.POSTHOG_HOST,
150150
})
151151

@@ -170,7 +170,7 @@ import os
170170
from posthog import Posthog
171171

172172
posthog = Posthog(
173-
os.environ["POSTHOG_PROJECT_API_KEY"],
173+
os.environ["POSTHOG_PROJECT_TOKEN"],
174174
host=os.environ["POSTHOG_HOST"], # https://us.i.posthog.com or https://eu.i.posthog.com
175175
)
176176
```
@@ -193,7 +193,7 @@ analytics = instrument(server, posthog) # wrap right after constructing the ser
193193
import time
194194
from posthog.mcp import PostHogMCP
195195

196-
posthog = PostHogMCP(os.environ["POSTHOG_PROJECT_API_KEY"], host=os.environ["POSTHOG_HOST"])
196+
posthog = PostHogMCP(os.environ["POSTHOG_PROJECT_TOKEN"], host=os.environ["POSTHOG_HOST"])
197197

198198
# on the initialize handshake:
199199
posthog.capture_initialize(client_name=client_name, client_version=client_version, distinct_id=distinct_id)
@@ -216,10 +216,10 @@ Resolve `distinct_id` / `session_id` from whatever auth/session the dispatcher a
216216

217217
### STEP 5: Wire up credentials
218218

219-
- Check existing env files (`.env`, `.env.local`, etc.) for a PostHog project API key. If a valid `phc_…` key and host are already set, reference those and skip the rest of this step.
220-
- If the key is missing, use the PostHog MCP server's `projects-get` tool to fetch the project's `api_token`. If multiple projects come back, ask the user which to use. If the MCP server isn't connected, ask the user for their project API key directly.
219+
- Check existing env files (`.env`, `.env.local`, etc.) for a PostHog project token. If a valid `phc_…` token and host are already set, reference those and skip the rest of this step.
220+
- If the token is missing, use the PostHog MCP server's `projects-get` tool to fetch the project's `api_token`. If multiple projects come back, ask the user which to use. If the MCP server isn't connected, ask the user for their project token directly.
221221
- Host: `https://us.i.posthog.com` for US Cloud, `https://eu.i.posthog.com` for EU Cloud.
222-
- Write `POSTHOG_PROJECT_API_KEY` and `POSTHOG_HOST` to the appropriate env file and reference them in code (`process.env.*` in JS, `os.environ[...]` in Python) — never hardcode the key.
222+
- Write `POSTHOG_PROJECT_TOKEN` and `POSTHOG_HOST` to the appropriate env file and reference them in code (`process.env.*` in JS, `os.environ[...]` in Python) — never hardcode the token.
223223

224224
### STEP 6: Ensure events get flushed
225225

@@ -260,7 +260,7 @@ The PostHog client batches events; the user owns the client's lifecycle.
260260

261261
- **One server, one wrapper.** `instrument()` is idempotent; don't call it twice on the same server.
262262
- **Module-scope client.** Construct the `PostHog` / `Posthog` / `PostHogMCP` client once, not per request.
263-
- **Env, never hardcode.** The project API key and host come from environment variables.
263+
- **Env, never hardcode.** The project token and host come from environment variables.
264264
- **Additive only.** Don't change tool behavior or restructure the server — just wrap/capture.
265265
- **Don't break STDIO.** No `console.*` (JS) or `print()` (Python) on STDIO transports; use a `logger` instead.
266266
- **Pin the beta SDK** and tell the user it's pre-1.0. (Python: `posthog.mcp` ships inside `posthog`; pin `posthog>=7.21`.)

context/skills/omnibus/instrument-error-tracking/description.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ STEP 6: Upload source maps (frontend/mobile only).
3838

3939
STEP 7: Set up environment variables.
4040
- Check if the project already has PostHog environment variables configured (e.g. in `.env`, `.env.local`, or framework-specific env files). If valid values already exist, skip this step.
41-
- If the PostHog API key is missing, use the PostHog MCP server's `projects-get` tool to retrieve the project's `api_token`. If multiple projects are returned, ask the user which project to use. If the MCP server is not connected or not authenticated, ask the user for their PostHog project API key instead.
41+
- If the PostHog project token is missing, use the PostHog MCP server's `projects-get` tool to retrieve the project's `api_token`. If multiple projects are returned, ask the user which project to use. If the MCP server is not connected or not authenticated, ask the user for their PostHog project token instead.
4242
- For the PostHog host URL, use `https://us.i.posthog.com` for US Cloud or `https://eu.i.posthog.com` for EU Cloud.
4343
- Write these values to the appropriate env file using the framework's naming convention.
4444
- Reference these environment variables in code instead of hardcoding them.

context/skills/omnibus/instrument-feature-flags/description.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ STEP 5: Instrument the feature.
3535

3636
STEP 6: Set up environment variables.
3737
- Check if the project already has PostHog environment variables configured (e.g. in `.env`, `.env.local`, or framework-specific env files). If valid values already exist, skip this step.
38-
- If the PostHog API key is missing, use the PostHog MCP server's `projects-get` tool to retrieve the project's `api_token`. If multiple projects are returned, ask the user which project to use. If the MCP server is not connected or not authenticated, ask the user for their PostHog project API key instead.
38+
- If the PostHog project token is missing, use the PostHog MCP server's `projects-get` tool to retrieve the project's `api_token`. If multiple projects are returned, ask the user which project to use. If the MCP server is not connected or not authenticated, ask the user for their PostHog project token instead.
3939
- For the PostHog host URL, use `https://us.i.posthog.com` for US Cloud or `https://eu.i.posthog.com` for EU Cloud.
4040
- Write these values to the appropriate env file using the framework's naming convention.
4141
- Reference these environment variables in code instead of hardcoding them.

context/skills/omnibus/instrument-integration/description.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ STEP 5: Identify users.
3232

3333
STEP 6: Set up environment variables.
3434
- Check if the project already has PostHog environment variables configured (e.g. in `.env`, `.env.local`, or framework-specific env files). If valid values already exist, skip this step.
35-
- If the PostHog API key is missing, use the PostHog MCP server's `projects-get` tool to retrieve the project's `api_token`. If multiple projects are returned, ask the user which project to use. If the MCP server is not connected or not authenticated, ask the user for their PostHog project API key instead.
35+
- If the PostHog project token is missing, use the PostHog MCP server's `projects-get` tool to retrieve the project's `api_token`. If multiple projects are returned, ask the user which project to use. If the MCP server is not connected or not authenticated, ask the user for their PostHog project token instead.
3636
- For the PostHog host URL, use `https://us.i.posthog.com` for US Cloud or `https://eu.i.posthog.com` for EU Cloud.
3737
- Write these values to the appropriate env file (e.g. `.env.local` for Next.js, `.env` for others) using the framework's naming convention.
3838
- Reference these environment variables in code instead of hardcoding them.

context/skills/omnibus/instrument-llm-analytics/description.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ STEP 5: Link to users.
3636

3737
STEP 6: Set up environment variables.
3838
- Check if the project already has PostHog environment variables configured (e.g. in `.env`, `.env.local`, or framework-specific env files). If valid values already exist, skip this step.
39-
- If the PostHog API key is missing, use the PostHog MCP server's `projects-get` tool to retrieve the project's `api_token`. If multiple projects are returned, ask the user which project to use. If the MCP server is not connected or not authenticated, ask the user for their PostHog project API key instead.
39+
- If the PostHog project token is missing, use the PostHog MCP server's `projects-get` tool to retrieve the project's `api_token`. If multiple projects are returned, ask the user which project to use. If the MCP server is not connected or not authenticated, ask the user for their PostHog project token instead.
4040
- For the PostHog host URL, use `https://us.i.posthog.com` for US Cloud or `https://eu.i.posthog.com` for EU Cloud.
4141
- Write these values to the appropriate env file using the framework's naming convention.
4242
- Reference these environment variables in code instead of hardcoding them.

context/skills/omnibus/instrument-logs/description.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ STEP 6: Add structured properties.
3939

4040
STEP 7: Set up environment variables.
4141
- Check if the project already has PostHog environment variables configured (e.g. in `.env`, `.env.local`, or framework-specific env files). If valid values already exist, skip this step.
42-
- If the PostHog API key is missing, use the PostHog MCP server's `projects-get` tool to retrieve the project's `api_token`. If multiple projects are returned, ask the user which project to use. If the MCP server is not connected or not authenticated, ask the user for their PostHog project API key instead.
42+
- If the PostHog project token is missing, use the PostHog MCP server's `projects-get` tool to retrieve the project's `api_token`. If multiple projects are returned, ask the user which project to use. If the MCP server is not connected or not authenticated, ask the user for their PostHog project token instead.
4343
- For the PostHog host URL, use `https://us.i.posthog.com` for US Cloud or `https://eu.i.posthog.com` for EU Cloud.
4444
- For the OpenTelemetry endpoint, use `https://us.i.posthog.com/v1` (US) or `https://eu.i.posthog.com/v1` (EU).
4545
- Write these values to the appropriate env file using the framework's naming convention.

context/skills/omnibus/instrument-product-analytics/description.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ STEP 8: Add error tracking.
4747

4848
STEP 9: Set up environment variables.
4949
- Check if the project already has PostHog environment variables configured (e.g. in `.env`, `.env.local`, or framework-specific env files). If valid values already exist, skip this step.
50-
- If the PostHog API key is missing, use the PostHog MCP server's `projects-get` tool to retrieve the project's `api_token`. If multiple projects are returned, ask the user which project to use. If the MCP server is not connected or not authenticated, ask the user for their PostHog project API key instead.
50+
- If the PostHog project token is missing, use the PostHog MCP server's `projects-get` tool to retrieve the project's `api_token`. If multiple projects are returned, ask the user which project to use. If the MCP server is not connected or not authenticated, ask the user for their PostHog project token instead.
5151
- For the PostHog host URL, use `https://us.i.posthog.com` for US Cloud or `https://eu.i.posthog.com` for EU Cloud.
5252
- Write these values to the appropriate env file using the framework's naming convention.
5353
- Reference these environment variables in code instead of hardcoding them.

example-apps/expo/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ PostHog is configured in `src/config/posthog.ts` using environment variables fro
105105
```typescript
106106
import Constants from 'expo-constants'
107107

108-
const apiKey = Constants.expoConfig?.extra?.posthogProjectToken
108+
const projectToken = Constants.expoConfig?.extra?.posthogProjectToken
109109
```
110110

111111
### Event Tracking

0 commit comments

Comments
 (0)