Skip to content

Commit 0a45f11

Browse files
authored
Merge pull request #53 from PostHog/refine-startup-for-existing-projects
Handle upgrading existing projects more gracefully
2 parents 6de5e77 + 11d6508 commit 0a45f11

File tree

2 files changed

+31
-106
lines changed

2 files changed

+31
-106
lines changed

README.md

Lines changed: 27 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -2,69 +2,25 @@
22

33
We've got live, working example code that demonstrates PostHog in action. You can run these yourself to see events flow into your PostHog project.
44

5-
## These are not production-grade
5+
## Example apps are not production-grade
66

77
These are more like model airplanes. They're dramatically simplified to make it easy to see PostHog in action. You shouldn't use these as starter projects or put them into production. The authentication is fake!
88

99
But the leanness makes these useful for agent-driven development. Use these as context to help your agent make better integration decisions about PostHog.
1010

1111
## Contents
1212

13-
More examples coming soon.
14-
1513
```
1614
examples/
1715
├── basics/
18-
│ ├── next-app-router/ # Next.js 15 with App Router
19-
│ │ ├── src/
20-
│ │ │ ├── app/
21-
│ │ │ │ ├── api/
22-
│ │ │ │ │ └── auth/
23-
│ │ │ │ │ └── login/
24-
│ │ │ │ │ └── route.ts # Server-side login API
25-
│ │ │ │ ├── burrito/
26-
│ │ │ │ │ └── page.tsx # Burrito consideration page
27-
│ │ │ │ ├── profile/
28-
│ │ │ │ │ └── page.tsx # User profile page
29-
│ │ │ │ ├── layout.tsx # Root layout with providers
30-
│ │ │ │ ├── page.tsx # Home/Login page
31-
│ │ │ │ └── globals.css # Global styles
32-
│ │ │ ├── components/
33-
│ │ │ │ └── Header.tsx # Navigation header
34-
│ │ │ ├── contexts/
35-
│ │ │ │ └── AuthContext.tsx # Auth context with PostHog
36-
│ │ │ └── lib/
37-
│ │ │ ├── posthog-server.ts # Server-side PostHog client
38-
│ │ │ └── instrumentation-client.ts # Client-side PostHog init
39-
│ │ ├── next.config.ts # Next.js config with rewrites
40-
│ │ ├── package.json
41-
│ │ └── README.md
42-
│ │
43-
│ └── next-pages-router/ # Next.js 15 with Pages Router
44-
│ ├── src/
45-
│ │ ├── pages/
46-
│ │ │ ├── api/
47-
│ │ │ │ └── auth/
48-
│ │ │ │ └── login.ts # Server-side login API
49-
│ │ │ ├── _app.tsx # App wrapper with providers
50-
│ │ │ ├── _document.tsx # Document wrapper
51-
│ │ │ ├── index.tsx # Home/Login page
52-
│ │ │ ├── burrito.tsx # Burrito consideration page
53-
│ │ │ └── profile.tsx # User profile page
54-
│ │ ├── components/
55-
│ │ │ └── Header.tsx # Navigation header
56-
│ │ ├── contexts/
57-
│ │ │ └── AuthContext.tsx # Auth context with PostHog
58-
│ │ ├── lib/
59-
│ │ │ ├── posthog-client.ts # Client-side PostHog init
60-
│ │ │ └── posthog-server.ts # Server-side PostHog client
61-
│ │ └── styles/
62-
│ │ └── globals.css # Global styles
63-
│ ├── next.config.ts # Next.js config with rewrites
64-
│ ├── package.json
65-
│ └── README.md
66-
67-
└── README.md # This file
16+
│ ├── next-app-router/ # Next.js 15 with App Router
17+
│ ├── next-pages-router/ # Next.js 15 with Pages Router
18+
│ ├── react-react-router/ # React with React Router
19+
│ ├── react-tanstack-router/ # React with TanStack Router
20+
│ └── tanstack-start/ # TanStack Start
21+
├── llm-prompts/ # Workflow guides for AI agents
22+
├── mcp-commands/ # MCP command prompts (`/command` in agents, can wrap `llm-prompts`)
23+
└── scripts/ # Build scripts
6824
```
6925

7026
## Examples
@@ -79,73 +35,41 @@ Next.js 15 with App Router demonstrating:
7935
- Reverse proxy setup for PostHog ingestion
8036
- Session replay (automatic)
8137

82-
**Key differences:**
83-
- Uses App Router (`src/app/` directory structure)
84-
- Server Components by default
85-
- `'use client'` directive for client components
86-
- Route handlers (`route.ts`) for API routes
87-
- Metadata via `layout.tsx` exports
88-
8938
### basics/next-pages-router
9039

91-
Same functionality as App Router example, but using Pages Router:
92-
- Client-side and server-side PostHog initialization
93-
- User identification and authentication
94-
- Event tracking (login, logout, custom events)
95-
- Error tracking with `posthog.captureException()`
96-
- Reverse proxy setup for PostHog ingestion
97-
- Session replay (automatic)
98-
99-
**Key differences:**
100-
- Uses Pages Router (`src/pages/` directory structure)
101-
- Client-side rendering by default
102-
- No `'use client'` directive needed
103-
- API routes in `src/pages/api/`
104-
- Metadata via `next/head` component
105-
- Custom `_app.tsx` and `_document.tsx`
40+
Same functionality as App Router example, using Pages Router patterns.
10641

10742
### basics/react-react-router
10843

109-
Coming soon.
44+
React SPA with React Router demonstrating PostHog integration in a client-side app.
11045

11146
### basics/react-tanstack-router
11247

113-
Coming soon.
48+
React SPA with TanStack Router demonstrating PostHog integration with file-based routing.
11449

115-
## Getting started
50+
### basics/tanstack-start
11651

117-
Each example includes its own README with setup instructions. Generally:
52+
Full-stack TanStack Start app with PostHog integration.
11853

119-
1. Navigate to the example directory
120-
2. Install dependencies: `pnpm install`
121-
3. Create `.env.local` with your PostHog credentials
122-
4. Run the dev server: `pnpm run dev`
54+
## MCP resources
12355

124-
See individual example READMEs for detailed instructions.
56+
This repository serves as the **single source of truth** for PostHog integration resources accessed via the [PostHog MCP server](https://github.com/PostHog/posthog/tree/master/products/mcp).
12557

126-
## MCP manifest architecture
58+
### Build outputs
12759

128-
This repository serves as the **single source of truth** for PostHog integration resources accessed via the [PostHog MCP server](https://github.com/PostHog/posthog/tree/main/products/mcp).
60+
Run `npm run build:docs` to generate:
12961

130-
### How it works
131-
132-
1. **Build process** (`npm run build:docs`):
133-
- Converts example projects to markdown
134-
- Discovers workflow guides from `llm-prompts/`
135-
- Discovers MCP prompts from `mcp-commands/`
136-
- Generates `manifest.json` with all URIs and metadata
137-
- Packages everything into `examples-mcp-resources.zip`
138-
139-
2. **MCP server** (runtime):
140-
- Fetches the ZIP from GitHub releases
141-
- Loads `manifest.json`
142-
- **Purely reflects** the manifest - no hardcoded URIs or logic
62+
| Output | Description |
63+
|--------|-------------|
64+
| `dist/*.md` | Example projects converted to markdown |
65+
| `dist/manifest.json` | Resource URIs and metadata |
66+
| `dist/examples-mcp-resources.zip` | Complete archive for MCP server |
14367

14468
### Manifest structure
14569

14670
The manifest defines:
14771
- **Workflows**: Step-by-step guides with automatic next-step linking
148-
- **Docs**: PostHog documentation URLs
72+
- **Docs**: PostHog documentation URLs (fetched at runtime)
14973
- **Prompts**: MCP command prompts with template variable substitution
15074
- **Templates**: Resource templates for parameterized access (e.g., `posthog://examples/{framework}`)
15175

@@ -159,12 +83,11 @@ The manifest defines:
15983

16084
The build script automatically discovers, orders, and generates URIs for all resources.
16185

162-
### Why this architecture?
86+
### Architecture
16387

164-
- **Single source of truth**: All URIs defined in examples repo
165-
- **Zero hardcoding**: MCP server has no URIs or business logic
88+
- **Single source of truth**: All URIs defined in this repo
89+
- **Zero hardcoding**: MCP server purely reflects the manifest for `resources` and `prompts` (as defined in the MCP [spec](https://modelcontextprotocol.io/specification/2025-11-25#features))
16690
- **Easy to extend**: Add resources by creating properly named files
16791
- **Version controlled**: Resources evolve with the examples
16892

16993
See `llm-prompts/README.md` for detailed workflow conventions.
170-

llm-prompts/basic-integration/1.0-begin.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ description: Start the event tracking setup process by analyzing the project and
55

66
We're making an event tracking plan for this project.
77

8-
From the project's file list, select between 10 and 15 files that might have interesting business value for event tracking, especially conversion and churn events. Also look for additional files related login that could be used for identifying users, along with error handling. Read the files.
8+
Before proceeding, find any existing `posthog.capture()` code. Make note of event name formatting.
99

10-
Create a new file with a JSON array at the root of the project: .posthog-events.json. It should include one object for each event we want to add: event name, event description, and the file path we want to place the event in.
10+
From the project's file list, select between 10 and 15 files that might have interesting business value for event tracking, especially conversion and churn events. Also look for additional files related login that could be used for identifying users, along with error handling. Read the files. If a file is already well-covered by PostHog events, replace it with another option.
11+
12+
Create a new file with a JSON array at the root of the project: .posthog-events.json. It should include one object for each event we want to add: event name, event description, and the file path we want to place the event in. If events already exist, don't duplicate them; supplement them.
1113

1214
Track actions only, not pageviews. These can be captured automatically. Exceptions can be made for "viewed"-type events that correspond to the top of a conversion funnel.
1315

0 commit comments

Comments
 (0)