Elffuss BraidHub

kikocis/continue public

4131ae02de3e ยท 18.6 KiBRawPermalink
1---
2title: "Building a Continuous AI Workflow with PostHog and GitHub"
3description: "Build an automated system that continuously monitors PostHog session recordings, analyzes UX issues using Continue CLI, and creates GitHub issues automatically."
4sidebarTitle: "PostHog Session Analysis with Continue CLI"
5---
6
7<Card title="What You'll Build" icon="robot">
8 A fully automated workflow that uses Continue CLI to fetch PostHog session
9 data, analyze user experience issues with AI, and automatically create GitHub
10 issues with specific technical recommendations
11</Card>
12
13## Prerequisites
14
15Before starting, ensure you have:
16
17- GitHub repository where you want to create issues
18- PostHog account with **[session recordings enabled and collecting data](https://posthog.com/docs/session-replay/installation)**
19- Node.js 18+ installed locally
20- Continue CLI account with **active credits** (required for API usage)
21
22<Steps>
23 <Step title="Install Continue CLI">
24 ```bash
25 npm i -g @continuedev/cli
26 ```
27 </Step>
28
29 <Step title="Set up Continue CLI Account & API Key">
30 1. Visit [Continue Organizations](https://hub.continue.dev/settings/organizations)
31 2. Sign up or log in to your Continue account
32 3. Navigate to your organization settings
33 4. Click **"API Keys"** and then **"+ New API Key"**
34 5. Copy the API key immediately (you won't see it again!)
35 6. Login to the CLI: `cn login`
36 </Step>
37
38 <Step title="Add Required Secrets to Continue CLI">
39 Continue CLI will securely store your API keys as secrets that can be referenced in prompts.
40 </Step>
41</Steps>
42
43<Tip>
44 Continue CLI handles all the complex API interactions - you just need to
45 provide the right prompts!
46</Tip>
47
48## Step 1: Set Up Your Credentials
49
50First, you'll need to gather your API credentials and add them as secrets in Continue CLI.
51
52### Get Your PostHog API Credentials
53
54You need a **Personal API Key** (not a Project API key) to access session recordings:
55
561. Go to [Personal API Keys](https://app.posthog.com/settings/user-api-keys) in PostHog
572. Click **+ Create a personal API Key**
583. Name it "Continue CLI Session Analysis"
594. Select these scopes:
60 - `session_recording:read` - **Required** for accessing session data
61 - `insight:read` - Optional, for additional analytics
625. Copy the key immediately (you won't see it again!)
63
64<Tip>
65 **Find Your Project Details**: Your Project ID is in your PostHog URL:
66 `https://app.posthog.com/project/YOUR_PROJECT_ID`
67</Tip>
68
69### Get Your GitHub Personal Access Token
70
711. Go to [GitHub Personal Access Tokens](https://github.com/settings/personal-access-tokens/new)
722. Click **"Generate new token (classic)"**
733. Name it "Continue CLI PostHog Analysis"
744. Select these scopes:
75 - `repo` (or just `public_repo` if your repository is public)
76 - `issues:write` - **Required** for creating issues
775. Copy the token immediately
78
79### Add Secrets to Continue CLI
80
81Use Continue CLI's built-in environment setup helper:
82
83```bash
84cn -p "Help me set up my environment for PostHog session analysis. Please:
851. Check if I have the required secrets configured in Continue CLI:
86 - POSTHOG_API_KEY
87 - POSTHOG_PROJECT_ID
88 - POSTHOG_HOST
89 - GITHUB_PAT
902. If any are missing, guide me through:
91 - How to get PostHog Personal API Key from PostHog settings
92 - How to find my PostHog Project ID from the URL
93 - How to create a GitHub Personal Access Token with issues:write permission
94 - How to add these as secrets in Continue CLI
953. Help me identify my GitHub repository owner and name by:
96 - Checking git remote origin URL
97 - Or asking me to provide them
984. Test the API connections by making a simple API call to both PostHog and GitHub to verify the credentials work.
99Please walk me through this setup process step by step."
100```
101
102<Info>
103 Continue CLI will guide you through adding secrets and testing your API
104 connections. Follow the prompts to add: - `POSTHOG_API_KEY`: Your PostHog
105 Personal API Key - `POSTHOG_PROJECT_ID`: Your PostHog Project ID -
106 `POSTHOG_HOST`: `https://us.posthog.com` (or your custom PostHog host) -
107 `GITHUB_PAT`: Your GitHub Personal Access Token
108</Info>
109
110## Step 2: Analyze PostHog Sessions with Continue CLI
111
112Now you'll use Continue CLI to fetch PostHog session data and analyze it for UX issues. Continue CLI handles all the API calls and analysis automatically.
113
114### Run the Analysis
115
116Use this prompt with Continue CLI to fetch and analyze your PostHog sessions:
117
118```bash
119cn -p "I need you to help me analyze PostHog session recordings to identify UX issues. Please:
120
1211. First, fetch session recordings from PostHog using these details:
122 - Use the POSTHOG_API_KEY, POSTHOG_PROJECT_ID, and POSTHOG_HOST from my secrets
123 - API endpoint: {POSTHOG_HOST}/api/projects/{POSTHOG_PROJECT_ID}/session_recordings/?limit=20
124 - Include Authorization header: 'Bearer {POSTHOG_API_KEY}'
125
1262. Filter the sessions to find problematic ones with either:
127 - console_error_count > 0 (JavaScript errors)
128 - recording_duration > 300 (sessions longer than 5 minutes)
129
1303. Analyze the filtered sessions and create exactly 3 GitHub issues for the most critical UX problems.
131
1324. Format each issue like this:
133### 1. **Issue Title Here**
134**Problem**: One sentence describing the user problem
135**Technical Causes**: Brief technical explanation
136**Affected Pages**: List the URLs
137**Recommended Fix**:
138- Specific action item 1
139- Specific action item 2
140**Priority**: **HIGH** or **MEDIUM** or **LOW**
141**Impact**: Quantify the impact (e.g., 'Affects 80% of sessions')
142
143Please make the API call, analyze the data, and provide the 3 formatted issues. Base all recommendations on actual patterns in the session data."
144```
145
146<Info>
147 **What Continue CLI Does:** - Makes authenticated API calls to PostHog using
148 your stored secrets - Fetches and filters session recordings automatically -
149 Analyzes patterns in the data using AI - Generates structured issue
150 descriptions ready for GitHub
151</Info>
152
153<Tip>
154 Save the analysis output to a file by adding `> analysis-results.txt` to the
155 command if you want to review it later.
156</Tip>
157
158## Step 3: Create GitHub Issues Automatically
159
160Now use Continue CLI to create GitHub issues from your analysis results:
161
162```bash
163cn -p "I have analyzed PostHog session data and identified UX issues. Now I need you to create GitHub issues using the GitHub API.
164
165Use these details from my secrets:
166- GITHUB_PAT: My GitHub Personal Access Token
167- Repository: Extract from git remote or ask me to specify
168
169For each issue in my analysis:
1701. Parse the issue title, body content, and priority level
1712. Create a GitHub issue via API POST to: https://api.github.com/repos/{owner}/{repo}/issues
1723. Use these headers:
173 - Authorization: token {GITHUB_PAT}
174 - Accept: application/vnd.github.v3+json
175 - Content-Type: application/json
1764. Set labels based on priority:
177 - HIGH: [\"bug\", \"high-priority\", \"user-experience\", \"automated\"]
178 - MEDIUM: [\"enhancement\", \"medium-priority\", \"user-experience\", \"automated\"]
179 - LOW: [\"low-priority\", \"user-experience\", \"automated\"]
1805. Format the issue title as: \"๐Ÿ” UX Issue: {original title}\"
181
182Please create the GitHub issues and confirm they were successfully created with issue numbers and URLs.
183"
184```
185
186<Warning>
187**Repository Labels Required**: Make sure your GitHub repository has these labels:
188- `bug`, `enhancement`
189- `high-priority`, `medium-priority`, `low-priority`
190- `user-experience`, `automated`
191
192Create missing labels in your repo at: **Settings โ†’ Labels โ†’ New label**
193
194</Warning>
195
196<Info>
197 **What Continue CLI Does:** - Parses your analysis results automatically -
198 Makes authenticated GitHub API calls using your stored token - Creates
199 properly formatted issues with appropriate labels - Checks for duplicate
200 issues to avoid spam - Provides confirmation with issue URLs
201</Info>
202
203## Step 4: Set Up Automated GitHub Actions Workflow
204
205Create a GitHub Actions workflow that runs your Continue CLI analysis automatically on a schedule.
206
207### Add GitHub Secrets
208
209First, add these secrets to your GitHub repository:
210
2111. Go to **Repository Settings โ†’ Secrets and variables โ†’ Actions**
2122. Click **"New repository secret"** and add:
213 - `CONTINUE_API_KEY`: Your Continue API key from hub.continue.dev
214 - `POSTHOG_API_KEY`: Your PostHog Personal API Key
215 - `POSTHOG_PROJECT_ID`: Your PostHog Project ID
216 - `POSTHOG_HOST`: `https://us.posthog.com` (or your custom PostHog host)
217 - `GITHUB_PAT`: Your GitHub Personal Access Token
218
219### Create GitHub Actions Workflow
220
221Create `.github/workflows/posthog-analysis.yml` in your repository:
222
223```yaml
224name: PostHog Session Analysis with Continue CLI
225
226on:
227 schedule:
228 - cron: "0 6 * * *" # Run at 6 AM UTC daily
229 workflow_dispatch: # Allow manual triggering
230
231jobs:
232 analyze:
233 runs-on: ubuntu-latest
234
235 permissions:
236 contents: read
237 issues: write
238
239 steps:
240 - uses: actions/checkout@v4
241
242 - name: Set up Node.js
243 uses: actions/setup-node@v4
244 with:
245 node-version: "18"
246
247 - name: Install Continue CLI
248 run: |
249 npm install -g @continuedev/cli
250 echo "โœ… Continue CLI installed"
251 cn --version
252
253 - name: Set up environment variables
254 run: |
255 echo "POSTHOG_API_KEY=${{ secrets.POSTHOG_API_KEY }}" >> $GITHUB_ENV
256 echo "POSTHOG_PROJECT_ID=${{ secrets.POSTHOG_PROJECT_ID }}" >> $GITHUB_ENV
257 echo "POSTHOG_HOST=${{ secrets.POSTHOG_HOST || 'https://us.posthog.com' }}" >> $GITHUB_ENV
258 echo "GITHUB_PAT=${{ secrets.GITHUB_PAT }}" >> $GITHUB_ENV
259 echo "GITHUB_OWNER=${{ github.repository_owner }}" >> $GITHUB_ENV
260 echo "GITHUB_REPO=$(echo ${{ github.repository }} | cut -d'/' -f2)" >> $GITHUB_ENV
261
262 - name: Authenticate with Continue CLI
263 run: |
264 # Set Continue API key
265 export CONTINUE_API_KEY="${{ secrets.CONTINUE_API_KEY }}"
266 # Login to Continue CLI
267 if ! cn auth login --api-key "$CONTINUE_API_KEY"; then
268 echo "โŒ Failed to authenticate with Continue CLI"
269 exit 1
270 fi
271 echo "โœ… Continue CLI authenticated"
272
273 - name: Run PostHog Session Analysis
274 run: |
275 echo "๐ŸŽฌ Starting PostHog session analysis..."
276 # Create the analysis prompt
277 cat > analysis_prompt.txt << 'EOF'
278 I need you to help me analyze PostHog session recordings to identify UX issues. Please:
279
280 1. First, fetch session recordings from PostHog using these details:
281 - Use the POSTHOG_API_KEY, POSTHOG_PROJECT_ID, and POSTHOG_HOST from environment variables
282 - API endpoint: $POSTHOG_HOST/api/projects/$POSTHOG_PROJECT_ID/session_recordings/?limit=20
283 - Include Authorization header: "Bearer $POSTHOG_API_KEY"
284
285 2. Filter the sessions to find problematic ones with either:
286 - console_error_count > 0 (JavaScript errors)
287 - recording_duration > 300 (sessions longer than 5 minutes)
288
289 3. Analyze the filtered sessions and create exactly 3 GitHub issues for the most critical UX problems.
290
291 4. Format each issue like this:
292 ### 1. **Issue Title Here**
293 **Problem**: One sentence describing the user problem
294 **Technical Causes**: Brief technical explanation
295 **Affected Pages**: List the URLs
296 **Recommended Fix**:
297 - Specific action item 1
298 - Specific action item 2
299 **Priority**: **HIGH** or **MEDIUM** or **LOW**
300 **Impact**: Quantify the impact (e.g., 'Affects 80% of sessions')
301
302 Please make the API call, analyze the data, and provide the 3 formatted issues. Base all recommendations on actual patterns in the session data.
303
304 Environment context:
305 - POSTHOG_API_KEY: $POSTHOG_API_KEY
306 - POSTHOG_PROJECT_ID: $POSTHOG_PROJECT_ID
307 - POSTHOG_HOST: $POSTHOG_HOST
308 - GitHub Repo: $GITHUB_OWNER/$GITHUB_REPO
309 EOF
310
311 # Run the analysis
312 cn < analysis_prompt.txt > analysis-results.txt 2>&1
313
314 # Check if analysis completed
315 if [ ! -s analysis-results.txt ]; then
316 echo "โŒ Analysis failed or produced no output"
317 exit 1
318 fi
319
320 echo "โœ… Analysis completed"
321 echo "๐Ÿ“„ Analysis results preview:"
322 head -20 analysis-results.txt
323
324 - name: Create GitHub Issues from Analysis
325 run: |
326 echo "๐Ÿ“ Creating GitHub issues from analysis..."
327 # Create the issue creation prompt
328 cat > issue_prompt.txt << 'EOF'
329 I have analyzed PostHog session data and identified UX issues. Now I need you to create GitHub issues using the GitHub API.
330
331 Use these details from environment variables:
332 - GITHUB_PAT: My GitHub Personal Access Token
333 - Repository: $GITHUB_OWNER/$GITHUB_REPO
334
335 For each issue in my analysis:
336 1. Parse the issue title, body content, and priority level
337 2. Create a GitHub issue via API POST to: https://api.github.com/repos/$GITHUB_OWNER/$GITHUB_REPO/issues
338 3. Use these headers:
339 - Authorization: token $GITHUB_PAT
340 - Accept: application/vnd.github.v3+json
341 - Content-Type: application/json
342 4. Set labels based on priority:
343 - HIGH: ["bug", "high-priority", "user-experience", "automated"]
344 - MEDIUM: ["enhancement", "medium-priority", "user-experience", "automated"]
345 - LOW: ["low-priority", "user-experience", "automated"]
346 5. Format the issue title as: "๐Ÿ” UX Issue: {original title}"
347
348 Please create the GitHub issues and confirm they were successfully created with issue numbers and URLs.
349
350 Here's my analysis to process:
351 EOF
352
353 # Append the analysis results to the prompt
354 cat analysis-results.txt >> issue_prompt.txt
355
356 # Run the issue creation
357 cn < issue_prompt.txt > issue-creation-results.txt 2>&1
358
359 echo "โœ… Issue creation completed"
360 echo "๐Ÿ“„ Issue creation results:"
361 cat issue-creation-results.txt
362
363 - name: Upload Analysis Artifacts
364 uses: actions/upload-artifact@v4
365 if: always()
366 with:
367 name: analysis-results-${{ github.run_number }}
368 path: |
369 analysis-results.txt
370 issue-creation-results.txt
371 retention-days: 30
372
373 - name: Summary
374 run: |
375 echo "โœ… PostHog analysis workflow completed!"
376 echo "๐Ÿ“Š Check the artifacts for detailed analysis results"
377 echo "๐Ÿ› Check your repository issues for newly created UX issues"
378```
379
380## Step 5: Testing Your Workflow
381
382### Test Locally First
383
384Before setting up automation, test the workflow locally:
385
386**Test 1: Session Analysis**
387
388```bash
389cn -p "[Paste the PostHog analysis prompt from Step 2]"
390```
391
392Expected: Analysis output with 3 formatted GitHub issues
393
394**Test 2: Issue Creation**
395
396```bash
397cn -p "[Paste the GitHub issue creation prompt from Step 3 with your analysis results]"
398```
399
400Expected: Confirmation of GitHub issues created with URLs
401
402### Test the GitHub Actions Workflow
403
4041. **Manual Trigger**: Go to **Actions** tab in your repository and manually trigger the workflow
4052. **Check Artifacts**: Download the analysis results from the workflow run
4063. **Verify Issues**: Check that GitHub issues were created in your repository
407
408<Check>
409 **Success Indicators:** - PostHog API returns session data (not empty) -
410 Continue CLI generates analysis with identified issues - GitHub issues are
411 created with proper labels and formatting - Workflow completes without errors
412</Check>
413
414## Troubleshooting
415
416If you encounter issues, use this helpful prompt to diagnose problems:
417
418```bash
419cn -p "Help me set up my environment for PostHog session analysis. Please:
420
4211. Check if I have the required secrets configured in Continue CLI:
422 - POSTHOG_API_KEY
423 - POSTHOG_PROJECT_ID
424 - POSTHOG_HOST
425 - GITHUB_PAT
426
4272. If any are missing, guide me through:
428 - How to get PostHog Personal API Key from PostHog settings
429 - How to find my PostHog Project ID from the URL
430 - How to create a GitHub Personal Access Token with issues:write permission
431 - How to add these as secrets in Continue CLI
432
4333. Help me identify my GitHub repository owner and name by:
434 - Checking git remote origin URL
435 - Or asking me to provide them
436
4374. Test the API connections by making a simple API call to both PostHog and GitHub to verify the credentials work.
438
439Please walk me through this setup process step by step."
440```
441
442## What You've Built
443
444After completing this guide, you have a complete **Continuous AI system** that:
445
446โœ… **Monitors user experience** - Automatically fetches and analyzes PostHog session data
447โœ… **Identifies problems intelligently** - Uses AI to spot patterns and technical issues
448โœ… **Creates actionable tasks** - Generates GitHub issues with specific recommendations
449โœ… **Runs autonomously** - Operates daily without manual intervention using GitHub Actions
450โœ… **Scales with your team** - Handles growing amounts of session data automatically
451
452<Card title="Continuous AI" icon="rocket">
453 Your system now operates at **[Level 2 Continuous
454 AI](https://blog.continue.dev/what-is-continuous-ai-a-developers-guide/)** -
455 AI handles routine analysis tasks with human oversight through GitHub issue
456 review and prioritization.
457</Card>
458
459## Security Best Practices
460
461<Warning>
462 **Protect Your API Keys:** - Store all credentials as GitHub Secrets, never in
463 code - Use Continue CLI's secure secret storage - Limit token scopes to
464 minimum required permissions - Rotate API keys regularly (every 90 days
465 recommended) - Monitor token usage for unusual activity
466</Warning>
467
468## Advanced Prompts
469
470Consider enhancing your workflow with these advanced Continue CLI prompts:
471
472<CardGroup cols={2}>
473 <Card title="Performance Analysis" icon="chart-line">
474 "Analyze PostHog performance metrics alongside session recordings to
475 identify slow page loads affecting user experience"
476 </Card>
477 <Card title="Error Correlation" icon="bug">
478 "Cross-reference JavaScript console errors with user actions to identify the
479 root cause of UX issues"
480 </Card>
481 <Card title="Feature Flag Analysis" icon="flag">
482 "Analyze how PostHog feature flags impact user behavior in session
483 recordings"
484 </Card>
485 <Card title="Custom Slack Alerts" icon="slack">
486 "Create Slack alerts when critical UX issues are detected in PostHog
487 sessions"
488 </Card>
489</CardGroup>
490
491## Next Steps
492
4931. **Monitor your first issues** - Review the GitHub issues created and implement fixes
4942. **Measure impact** - Track how resolved issues improve PostHog metrics
4953. **Refine prompts** - Adjust the Continue CLI prompts based on issue quality
4964. **Scale the system** - Add more data sources or create specialized analysis workflows