Elffuss BraidHub

kikocis/continue public

main ยท 18.9 KiBRawPermalink
1---
2title: "Building a Continuous AI Workflow with PostHog and GitHub"
3description: "Build an automated system that continuously monitors PostHog analytics, analyzes user behavior with AI, and creates GitHub issues automatically using PostHog MCP."
4sidebarTitle: "PostHog Analytics with Continue CLI"
5---
6
7<Card title="What You'll Build" icon="robot">
8 A fully automated workflow that uses Continue CLI with the PostHog MCP to fetch analytics data, analyze user experience issues with AI, and automatically create GitHub
9 issues with the GitHub CLI.
10</Card>
11
12## What You'll Learn
13
14This cookbook teaches you to:
15
16- Use [PostHog MCP](https://posthog.com/docs/model-context-protocol) to query [analytics](https://posthog.com/docs/web-analytics), [errors](https://posthog.com/docs/error-tracking), and [feature flags](https://posthog.com/docs/feature-flags)
17- Analyze user behavior patterns with AI
18- Automatically create GitHub issues using GitHub CLI
19- Set up continuous monitoring with GitHub Actions
20
21## Prerequisites
22
23Before starting, ensure you have:
24
25- GitHub repository where you want to create issues
26- [PostHog account](https://posthog.com) with [session recordings enabled](https://posthog.com/docs/session-replay/installation) and data collecting
27- Node.js 18+ installed locally
28- [Continue CLI](https://docs.continue.dev/guides/cli) with **active credits** (required for API usage)
29- [GitHub CLI](https://cli.github.com/) installed (`gh` command)
30
31<Steps>
32 <Step title="Install Continue CLI">
33 ```bash
34 npm i -g @continuedev/cli
35 ```
36 </Step>
37
38 <Step title="Set up Continue CLI Account & API Key">
39 1. Visit [Continue Organizations](https://hub.continue.dev/settings/organizations)
40 2. Sign up or log in to your Continue account
41 3. Navigate to your organization settings
42 4. Click **"API Keys"** and then **"+ New API Key"**
43 5. Copy the API key immediately (you won't see it again!)
44 6. Login to the CLI: `cn login`
45 </Step>
46
47 <Step title="Add Required Secrets to Continue CLI">
48 Continue CLI will securely store your API keys as secrets that can be referenced in prompts.
49 </Step>
50</Steps>
51
52<Tip>
53 Continue CLI handles the complex API interactions - you just need to provide
54 the right prompts!
55</Tip>
56
57## Step 1: Set Up Your Credentials
58
59First, you'll need to gather your PostHog and GitHub API credentials and add them as secrets in Continue CLI.
60
61<Tabs>
62 <Tab title="PostHog API Credentials">
63 You'll need a **Personal API Key** (not a Project API key) to access session recordings:
64
65 1. Go to [Personal API Keys](https://app.posthog.com/settings/user-api-keys) in PostHog
66 2. Click **+ Create a personal API Key**
67 3. Name it "Continue CLI Session Analysis"
68 4. Select these scopes:
69 - `session_recording:read` - **Required** for accessing session data
70 - `insight:read`
71 - `query:read`
72 - `session_recording_playlist:read`
73 5. Copy the key immediately (you won't see it again!)
74 6. Note your **Project ID** from your PostHog project settings
75 7. Note your PostHog host URL (e.g., `https://us.posthog.com` or your custom domain)
76 8. You'll also need your POSTHOG_AUTH_HEADER value, which is simply `Bearer YOUR_API_KEY`
77
78 <Info>
79 **Continue Secrets**: The `POSTHOG_AUTH_HEADER` secret should be stored in
80 Continue's secure secrets storage. This keeps your API key safe and the MCP
81 automatically connects to your default PostHog project.
82</Info>
83
84 </Tab>
85 <Tab title="Set Up GitHub CLI Authentication">
86 GitHub CLI handles authentication automatically - no manual PAT needed:
87
88 1. Install GitHub CLI if not already installed
89 2. Run `gh auth login` and follow the prompts
90 3. Choose authentication method (browser or token)
91 4. Grant necessary permissions when prompted (`issues:write` is **required** for creating issues)
92
93 </Tab>
94<Tab title= "Configure API Access in Continue CLI">
95
96<Tip>
97See https://docs.continue.dev/hub/secrets/secret-types#secret-types for adding secrets
98</Tip>
99
100You only need to configure the PostHog MCP credential - it automatically handles project selection. To add environment variables to your Continue Hub account:
101
1021. Go to the [Continue Hub](https://hub.continue.dev)
1032. Sign in to your account
1043. Navigate to your user settings
1054. Look for the "Secrets" section
1065. Add your Personal API Key from PostHog (phx_...) as POSTHOG_AUTH_HEADER secret with format: Bearer YOUR_API_KEY
107
108</Tab>
109</Tabs>
110
111## PostHog GitHub Continuous AI Workflow Options
112
113<Card title="๐Ÿš€ Fastest Path to Success" icon="zap">
114 Skip the manual setup and use our pre-built PostHog GitHub agent that includes
115 optimized prompts, rules, and the PostHog MCP for more consistent results.
116</Card>
117
118<Info>
119 **How PostHog MCP Works**:
120 - Your API key is tied to your PostHog account and
121 organization
122 - It automatically uses your default project (no project ID
123 needed)
124 - If you have multiple projects, use `mcp__posthog__switch-project` to
125 change
126 - The MCP connects via `https://mcp.posthog.com/sse` using your account context.
127
128</Info>
129
130<Tabs>
131 <Tab title="โšก Quick Start (Recommended)">
132 **Perfect for:** Immediate results with optimized prompts and built-in debugging
133
134 <Steps>
135 <Step title="Add the Pre-Built Agent">
136 Visit the [PostHog GitHub Continuous AI Agent](https://hub.continue.dev/continuedev/awesome-models-posthog-gh) on Continue Hub and click **"Install Agent"** or run:
137
138 ```bash
139 cn --config continuedev/awesome-models-posthog-gh
140 ```
141
142 This agent includes:
143 - **Optimized prompts** for [PostHog analysis](https://hub.continue.dev/continuedev/posthog-analysis) and [GitHub issue creation](https://hub.continue.dev/continuedev/posthog-github-issues)
144 - **[Built-in rules](https://hub.continue.dev/bekah-hawrot-weigel/posthog-github-continuous-ai-rules)** for consistent formatting and error handling
145 - **[PostHog MCP](https://hub.continue.dev/posthog/posthog-mcp)** for more reliable API interactions
146 </Step>
147
148 <Step title="Run the Analysis">
149 Navigate to your project directory and run:
150 ```bash
151 cn "Give me my PostHog Session data and create GitHub issues based on the problems."
152 ```
153
154 That's it! The agent handles everything automatically.
155 </Step>
156 </Steps>
157
158 <Info>
159 **Why Use the Agent?** Results are more consistent and debugging is easier thanks to the PostHog MCP integration and pre-tested prompts.
160 </Info>
161
162 </Tab>
163
164 <Tab title="๐Ÿ› ๏ธ Manual Setup">
165 <Steps>
166 <Step title="Add PostHog MCP to Continue CLI">
167 First, install the [PostHog MCP](https://hub.continue.dev/posthog/posthog-mcp) or run:
168 ```bash
169 npx -y mcp-remote@latest https://mcp.posthog.com/sse --header Authorization:${{ secrets.continuedev/awesome-models-posthog-gh/posthog/posthog-mcp/POSTHOG_AUTH_HEADER }}
170 ```
171 </Step>
172 <Step title="Add PostHog + GitHub Analysis Rules">
173 In the Continue Hub, add the [PostHog GitHub Continuous AI Rules](https://hub.continue.dev/bekah-hawrot-weigel/posthog-github-continuous-ai-rules) to your account for better formatting and error handling.
174 </Step>
175 <Step title="Create Your Custom Prompts">
176 Use this prompt with Continue CLI to analyze PostHog data and create GitHub issues:
177
178 ```bash
179
180 # In cn TUI mode:
181 "Create GitHub issues from the PostHog analysis using gh CLI:
182 - For each issue, run: gh issue create --title '๐Ÿ” UX Issue: [title]' --body '[details]'
183 - Add labels: --label 'bug,user-experience,automated'
184 - Set priority labels (high/medium/low)
185 - Include session data and technical details in the body
186 Execute the commands and confirm each issue was created with URL."
187 ```
188 </Step>
189</Steps>
190
191 </Tab>
192</Tabs>
193<Info>
194
195 **Why GitHub CLI over GitHub MCP**: While GitHub MCP is available, it can be
196 token-expensive to run. The `gh` CLI is more efficient, requires no API tokens
197 (authenticated via `gh auth login`), and provides a cleaner command-line
198 experience. GitHub MCP remains an option if you prefer full MCP integration.
199</Info>
200
201<Accordion title="Agent Requirements">
202 To use the pre-built agent, you need either:
203 - **Continue CLI Pro Plan** with
204 the models add-on, OR
205 - **Your own API keys** added to Continue Hub secrets
206 (same as Step 1 below) The agent will automatically detect and use your
207 configuration.
208
209</Accordion>
210
211---
212
213<Warning>
214**Repository Labels Required**: Make sure your GitHub repository has these labels:
215- `bug`, `enhancement`
216- `high-priority`, `medium-priority`, `low-priority`
217- `user-experience`, `automated`
218
219Create missing labels in your repo at: **Settings โ†’ Labels โ†’ New label**
220
221</Warning>
222
223<Info>
224 **What Continue CLI Does:** - Parses your analysis results automatically -
225 Makes authenticated GitHub API calls using your stored token - Creates
226 properly formatted issues with appropriate labels - Checks for duplicate
227 issues to avoid spam - Provides confirmation with issue URLs
228</Info>
229
230## Setting Up Automated GitHub Actions Workflow
231
232Create a GitHub Actions workflow that runs your Continue CLI analysis automatically on a schedule.
233
234### Add GitHub Secrets
235
236First, add these secrets to your GitHub repository:
237
2381. Go to **Repository Settings โ†’ Secrets and variables โ†’ Actions**
2392. Click **"New repository secret"** and add:
240 - `CONTINUE_API_KEY`: Your Continue API key from hub.continue.dev
241
242### Create GitHub Actions Workflow
243
244Create `.github/workflows/posthog-analysis.yml` in your repository:
245
246<Tabs>
247 <Tab title="โšก Using Pre-Built Agent (Recommended)">
248```yaml
249name: PostHog Session Analysis with Continue CLI Agent
250
251on:
252schedule: - cron: "0 6 \* \* \*" # Run at 6 AM UTC daily
253workflow_dispatch: # Allow manual triggering
254
255jobs:
256analyze:
257runs-on: ubuntu-latest
258
259 permissions:
260 contents: read
261 issues: write
262
263 steps:
264 - uses: actions/checkout@v4
265
266 - name: Set up Node.js
267 uses: actions/setup-node@v4
268 with:
269 node-version: "18"
270
271 - name: Install Continue CLI
272 run: |
273 npm install -g @continuedev/cli
274 echo "โœ… Continue CLI installed"
275 cn --version
276
277 - name: Authenticate with Continue CLI
278 run: |
279 # Set Continue API key
280 export CONTINUE_API_KEY="${{ secrets.CONTINUE_API_KEY }}"
281 # Login to Continue CLI
282 if ! cn auth login --api-key "$CONTINUE_API_KEY"; then
283 echo "โŒ Failed to authenticate with Continue CLI"
284 exit 1
285 fi
286 echo "โœ… Continue CLI authenticated"
287
288 - name: Load PostHog GitHub Agent
289 run: |
290 echo "๐Ÿค– Loading PostHog GitHub Continuous AI Agent..."
291 cn --config continuedev/awesome-models-posthog-gh
292 echo "โœ… Agent loaded successfully"
293
294 - name: Run PostHog Analysis and Create GitHub Issues
295 run: |
296 echo "๐ŸŽฌ Starting automated PostHog session analysis..."
297
298 # Run the agent with the simple prompt
299 cn -p "Tell me about my PostHog session recordings and create GitHub issues based on the problems."
300
301 echo "โœ… Analysis and issue creation completed"
302
303 - name: Summary
304 run: |
305 echo "โœ… PostHog analysis workflow completed!"
306 echo "๐Ÿ“Š Check the artifacts for detailed analysis results"
307 echo "๐Ÿ› Check your repository issues for newly created UX issues"
308 echo "๐Ÿค– Agent automatically handled both analysis and issue creation"
309 ```
310
311 </Tab>
312
313 <Tab title="๐Ÿ› ๏ธ Manual Setup Version">
314
315```yaml
316name: PostHog Session Analysis with Continue CLI Manual
317
318on:
319schedule: - cron: "0 6 \* \* \*" # Run at 6 AM UTC daily
320workflow_dispatch: # Allow manual triggering
321
322jobs:
323analyze:
324runs-on: ubuntu-latest
325
326 permissions:
327 contents: read
328 issues: write
329
330 steps:
331 - uses: actions/checkout@v4
332
333 - name: Set up Node.js
334 uses: actions/setup-node@v4
335 with:
336 node-version: "18"
337
338 - name: Install Continue CLI
339 run: |
340 npm install -g @continuedev/cli
341 echo "โœ… Continue CLI installed"
342 cn --version
343
344 - name: Authenticate with Continue CLI
345 run: |
346 # Set Continue API key
347 export CONTINUE_API_KEY="${{ secrets.CONTINUE_API_KEY }}"
348 # Login to Continue CLI
349 if ! cn auth login --api-key "$CONTINUE_API_KEY"; then
350 echo "โŒ Failed to authenticate with Continue CLI"
351 exit 1
352 fi
353 echo "โœ… Continue CLI authenticated"
354
355 - name: Run PostHog Session Analysis
356 run: |
357 echo "๐ŸŽฌ Starting PostHog session analysis..."
358 # Create the analysis prompt
359 I need you to help me analyze PostHog session recordings to identify UX issues. Please:
360
361 1. First, fetch session recordings from PostHog using these details:
362 - Use the POSTHOG_API_KEY, POSTHOG_PROJECT_ID, and POSTHOG_HOST from my secrets
363 - API endpoint: {POSTHOG_HOST}/api/projects/{POSTHOG_PROJECT_ID}/session_recordings/?limit=20
364 - Include Authorization header: 'Bearer {POSTHOG_API_KEY}'
365
366 2. Filter the sessions to find problematic ones with either:
367 - console_error_count > 0 (JavaScript errors)
368 - recording_duration > 300 (sessions longer than 5 minutes)
369
370 3. Analyze the filtered sessions and create exactly 3 GitHub issues for the most critical UX problems.
371
372 4. Format each issue like this:
373 ### 1. **Issue Title Here**
374 **Problem**: One sentence describing the user problem
375 **Technical Causes**: Brief technical explanation
376 **Affected Pages**: List the URLs
377 **Recommended Fix**:
378 - Specific action item 1
379 - Specific action item 2
380 **Priority**: **HIGH** or **MEDIUM** or **LOW**
381 **Impact**: Quantify the impact (e.g., 'Affects 80% of sessions')
382
383 Please make the API call, analyze the data, and provide the 3 formatted issues. Base all recommendations on actual patterns in the session data.
384 EOF
385
386 echo "โœ… Analysis completed"
387
388
389 - name: Create GitHub Issues from Analysis
390 run: |
391 echo "๐Ÿ“ Creating GitHub issues from analysis..."
392 # Create the issue creation prompt
393 I have analyzed PostHog session data and identified UX issues. Now I need you to create GitHub issues using the GitHub API.
394
395 For each issue in my analysis:
396 1. Parse the issue title, body content, and priority level
397 2. Create a GitHub issue via API POST to: https://api.github.com/repos/{owner}/{repo}/issues
398 3. Use these headers:
399 - Authorization: token {GITHUB_PAT}
400 - Accept: application/vnd.github.v3+json
401 - Content-Type: application/json
402 4. Set labels based on priority:
403 - HIGH: ["bug", "high-priority", "user-experience", "automated"]
404 - MEDIUM: ["enhancement", "medium-priority", "user-experience", "automated"]
405 - LOW: ["low-priority", "user-experience", "automated"]
406 5. Format the issue title as: "๐Ÿ” UX Issue: {original title}"
407
408 Please create the GitHub issues and confirm they were successfully created with issue numbers and URLs.
409
410 echo "โœ… Issue creation completed"
411
412 - name: Summary
413 run: |
414 echo "โœ… PostHog analysis workflow completed!"
415 echo "๐Ÿ› Check your repository issues for newly created UX issues"
416 ```
417
418 </Tab>
419</Tabs>
420
421### Test the GitHub Actions Workflow
422
4231. **Manual Trigger**: Go to **Actions** tab in your repository and manually trigger the workflow
4242. **Check Artifacts**: Download the analysis results from the workflow run
4253. **Verify Issues**: Check that GitHub issues were created in your repository
426
427<Check>
428
429 **Success Indicators:**
430 - PostHog API returns session data (not empty)
431 - Continue CLI generates analysis with identified issues
432 - GitHub issues are created with proper labels and formatting
433 - Workflow completes without errors
434
435</Check>
436
437## What You've Built
438
439After completing this guide, you have a complete **Continuous AI system** that:
440
441- **Monitors user experience** - Automatically fetches and analyzes PostHog session data
442
443- **Identifies problems intelligently** - Uses AI to spot patterns and technical issues
444
445- **Creates actionable tasks** - Generates GitHub issues with specific recommendations
446
447- **Runs autonomously** - Operates daily without manual intervention using GitHub Actions
448
449- **Scales with your team** - Handles growing amounts of session data automatically
450
451<Card title="Continuous AI" icon="rocket">
452 Your system now operates at **[Level 2 Continuous
453 AI](https://blog.continue.dev/what-is-continuous-ai-a-developers-guide/)** -
454 AI handles routine analysis tasks with human oversight through GitHub issue
455 review and prioritization.
456</Card>
457
458## Security Best Practices
459
460<Warning>
461
462 **Protect Your API Keys:**
463 - Store all credentials as GitHub Secrets, never in
464 code
465 - Use Continue CLI's secure secret storage
466 - Limit token scopes to minimum required permissions
467 - Rotate API keys regularly (every 90 days recommended)
468 - Monitor token usage for unusual activity
469
470</Warning>
471
472## Advanced Prompts
473
474Consider enhancing your workflow with these advanced Continue CLI prompts:
475
476<CardGroup cols={2}>
477 <Card title="Performance Analysis" icon="chart-line">
478 "Analyze [PostHog performance
479 metrics](https://posthog.com/docs/web-analytics) alongside session
480 recordings to identify slow page loads affecting user experience"
481 </Card>
482 <Card title="Error Correlation" icon="bug">
483 "Cross-reference JavaScript console errors with user actions to identify the
484 root cause of UX issues"
485 </Card>
486 <Card title="Feature Flag Analysis" icon="flag">
487 "Analyze how [PostHog feature flags](https://posthog.com/docs/feature-flags)
488 impact user behavior in session recordings"
489 </Card>
490 <Card title="Custom Slack Alerts" icon="slack">
491 "Create Slack alerts when critical UX issues are detected in PostHog
492 sessions"
493 </Card>
494</CardGroup>
495
496## Next Steps
497
498- Consider [GitHub MCP](https://hub.continue.dev/github/github-mcp) as an alternative (note: can be token-expensive)
499- Configure [Slack MCP](https://hub.continue.dev/slack/slack-mcp) for alerts
500- Set up [PostHog performance monitoring](https://posthog.com/docs/web-analytics)
501- Join the [Continue Discord](https://discord.gg/continue) for support
502
503## Resources
504
505- [PostHog API Documentation](https://posthog.com/docs/api)
506- [PostHog MCP Documentation](https://posthog.com/docs/model-context-protocol)
507- [PostHog Session Replay](https://posthog.com/docs/session-replay)
508- [PostHog Feature Flags](https://posthog.com/docs/feature-flags)
509- [PostHog Error Tracking](https://posthog.com/docs/error-tracking)
510- [GitHub CLI Documentation](https://cli.github.com/)
511- [GitHub MCP on Continue Hub](https://hub.continue.dev/github/github-mcp) (alternative option)
512- [Continue CLI Guide](https://docs.continue.dev/guides/cli)
513- [Continuous AI Best Practices](https://blog.continue.dev/what-is-continuous-ai-a-developers-guide/)