Skip to content

Commit ec39084

Browse files
authored
Merge pull request #31 from PostHog/move-workflow-guides-from-mcp
Migrate workflow guide prompts as example artifacts
2 parents 21fd2b7 + 5557296 commit ec39084

File tree

6 files changed

+130
-2
lines changed

6 files changed

+130
-2
lines changed

.github/workflows/build-release.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ jobs:
4040
- name: Build markdown documentation
4141
run: npm run build:docs
4242

43+
- name: List build artifacts
44+
run: ls -lh dist/
45+
4346
- name: Determine version
4447
id: version
4548
run: |
@@ -113,9 +116,11 @@ jobs:
113116
tag_name: ${{ steps.version.outputs.tag }}
114117
release_name: Release ${{ steps.version.outputs.tag }}
115118
body: |
116-
Automated release of PostHog example projects as markdown documentation.
119+
Automated release of PostHog example projects and LLM prompts as markdown documentation.
117120
118-
This release contains pre-processed markdown files for all example projects included in the build-examples-mcp-resources.js script.
121+
This release contains **examples-mcp-resources.zip** with:
122+
- Pre-processed markdown files for all example projects
123+
- LLM workflow guide prompts (in `prompts/` directory)
119124
120125
**Version:** ${{ steps.version.outputs.version }}
121126
**SHA:** ${{ github.sha }}

llm-prompts/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# LLM Prompts
2+
3+
This directory contains LLM workflow prompts that guide AI agents through various PostHog integration tasks.
4+
5+
Feel free to try these out directly, or summon them from the PostHog MCP server. You can also use them as a starting point for your own deep integrations. We've tested these extensively.
6+
7+
## Structure
8+
9+
- **basic-integration/**: Step-by-step workflow guides for adding PostHog event tracking to a project
10+
- `1.0-event-setup-begin.md`: Initial project analysis and event planning
11+
- `1.1-event-setup-edit.md`: Implementation guidance for adding PostHog tracking
12+
- `1.2-event-setup-revise.md`: Error checking and correction
13+
14+
## Build Process
15+
16+
These prompts are packaged into the release artifact `examples-mcp-resources.zip`.
17+
18+
## Usage
19+
20+
The MCP server fetches these prompts from the latest GitHub release and serves them as resources to AI agents and the PostHog wizard during integration tasks.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
We're making an event tracking plan for this project.
2+
3+
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.
4+
5+
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.
6+
7+
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.
8+
9+
As you review files, make an internal note of opportunities to identify users and catch errors. We'll need them for the next step.
10+
11+
## Status
12+
13+
Before beginning a phase of the setup, you will send a status message with the exact prefix '[STATUS]', as in:
14+
15+
[STATUS] Checking project structure.
16+
17+
Status to report in this phase:
18+
19+
- Checking project structure
20+
- Verifying PostHog dependencies
21+
- Generating events based on project
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
For each of the files and events noted in .posthog-events.json, make edits to capture events using PostHog. Make sure to set up any helper files needed. Carefully examine the included example project code: your implementation should match it as closely as possible.
2+
3+
Use environment variables for PostHog keys. Do not hardcode PostHog keys.
4+
5+
If a file already has existing integration code for other tools or services, don't overwrite or remove that code. Place PostHog code below it.
6+
7+
For each event, add useful properties, and use your access to the PostHog source code to ensure correctness. You also have access to documentation about creating new events with PostHog. Consider this documentation carefully and follow it closely before adding events. Your integration should be based on documented best practices. Carefully consider how the user project's framework version may impact the correct PostHog integration approach.
8+
9+
Remember that you can find the source code for any dependency in the node_modules directory. This may be necessary to properly populate property names.
10+
11+
Where possible, add calls for PostHog's identify() function on the client side. On the server side, make sure events have a matching distinct ID where relevant. Use the same ID for identify on the client as you use distinct ID on the server. Logins and signups are a great opportunity to identify users. Use the contents of login and signup forms to identify users on submit.
12+
13+
It's essential to do this in both client code and server code, so that user behavior from both domains is easy to correlate.
14+
15+
You should also add PostHog error tracking to these files where relevant.
16+
17+
Remember: Do not alter the fundamental architecture of existing files. Make your additions minimal and targeted.
18+
19+
Remember the documentation and example project resources you were provided at the beginning. Read them now.
20+
21+
## Status
22+
23+
Status to report in this phase:
24+
25+
- Inserting PostHog capture code
26+
- A status message for each file whose edits you are planning, including a high level summary of changes
27+
- A status message for each file you have edited
28+
29+
## Notes on react-based projects: PAY CLOSE ATTENTION
30+
31+
- NEVER USE useEffect(); this is brittle and causes errors. Instead, add appropriate event handlers in places where you are tempted to use useEffect(). This is appropriate to our analytics capture approach anyway.
32+
- Prefer event handlers or routing mechanisms to trigger analytics calls
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Check the project for errors. Read the package.json file for any type checking or build scripts that may provide input about what to fix. Remember that you can find the source code for any dependency in the node_modules directory.
2+
3+
## Status
4+
5+
Status to report in this phase:
6+
7+
- Finding and correcting errors
8+
- Report details of any errors you fix

scripts/build-examples-mcp-resources.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,29 @@ function convertProjectToMarkdown(absolutePath, frameworkInfo, relativePath, ski
249249
return markdown;
250250
}
251251

252+
/**
253+
* Recursively get all files in a directory (used for LLM prompts)
254+
*/
255+
function getAllFilesInDirectory(dirPath, arrayOfFiles = [], baseDir = dirPath) {
256+
const files = fs.readdirSync(dirPath);
257+
258+
files.forEach(file => {
259+
const filePath = path.join(dirPath, file);
260+
const relativePath = path.relative(baseDir, filePath);
261+
262+
if (fs.statSync(filePath).isDirectory()) {
263+
arrayOfFiles = getAllFilesInDirectory(filePath, arrayOfFiles, baseDir);
264+
} else if (file.endsWith('.md') && file !== 'README.md') {
265+
arrayOfFiles.push({
266+
fullPath: filePath,
267+
relativePath: relativePath,
268+
});
269+
}
270+
});
271+
272+
return arrayOfFiles;
273+
}
274+
252275
/**
253276
* Main build function
254277
*/
@@ -303,6 +326,25 @@ async function build() {
303326
console.log(` ✓ Generated ${outputFilename} (${(markdown.length / 1024).toFixed(1)} KB)`);
304327
}
305328

329+
// Process LLM prompts
330+
console.log('\nProcessing LLM prompts...');
331+
const promptsPath = path.join(__dirname, '..', 'llm-prompts');
332+
333+
if (fs.existsSync(promptsPath)) {
334+
const promptFiles = getAllFilesInDirectory(promptsPath, [], promptsPath);
335+
336+
for (const file of promptFiles) {
337+
markdownFiles.push({
338+
filename: `prompts/${file.relativePath}`,
339+
path: file.fullPath
340+
});
341+
}
342+
343+
console.log(` ✓ Added ${promptFiles.length} prompt files`);
344+
} else {
345+
console.warn(' Warning: LLM prompts directory not found');
346+
}
347+
306348
// Create ZIP archive
307349
console.log('\nCreating ZIP archive...');
308350
const zipPath = path.join(outputDir, 'examples-mcp-resources.zip');

0 commit comments

Comments
 (0)