You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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:
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
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.
0 commit comments