Skip to content

Commit fdf76a8

Browse files
dannyshmueliclaude
andcommitted
docs: add JS error tracking to skill
Step 2c: data-track-errors, query examples, routing table update. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 71f246e commit fdf76a8

1 file changed

Lines changed: 39 additions & 1 deletion

File tree

skill/SKILL.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,43 @@ https://yoursite.com/pricing/?aa_variant_signup_cta=new_cta&utm_campaign=new-cta
206206
- Let experiments run until `sufficient_data: true` before picking a winner
207207
- Complete the experiment when done: `experiments complete <id> --winner new_cta`
208208

209+
## Step 2c: Track JS errors
210+
211+
Add `data-track-errors="true"` to the tracking snippet to automatically capture JavaScript errors:
212+
213+
```html
214+
<script defer src="https://api.agentanalytics.sh/tracker.js"
215+
data-project="my-site" data-token="aat_..."
216+
data-track-errors="true"></script>
217+
```
218+
219+
**What it tracks:**
220+
- Uncaught exceptions (`window.addEventListener('error')`)
221+
- Unhandled promise rejections (`window.addEventListener('unhandledrejection')`)
222+
- Each error becomes a `$error` event with `{ message, source, line, col }`
223+
224+
**Safety features:**
225+
- Max 5 errors per page view (prevents runaway logging)
226+
- Deduplicates by message+source+line (same error on same line only tracked once)
227+
- Resets on SPA navigation
228+
- Does not interfere with other error handlers (additive, not overwriting)
229+
- No stack traces (keeps payloads small)
230+
231+
**Querying error data:**
232+
233+
```bash
234+
# Recent errors
235+
npx @agent-analytics/cli events my-site --event '$error' --days 7
236+
237+
# Error breakdown by message
238+
npx @agent-analytics/cli breakdown my-site --property message --event '$error'
239+
240+
# Errors per source file
241+
npx @agent-analytics/cli query my-site \
242+
--filter '[{"field":"event","op":"eq","value":"$error"}]' \
243+
--group-by properties.source --metrics event_count
244+
```
245+
209246
## Step 3: Test immediately
210247

211248
After adding tracking, verify it works:
@@ -342,6 +379,7 @@ Match the user's question to the right call(s):
342379
| "Events per country" | `query --group-by country --metrics event_count,unique_users` | Country breakdown |
343380
| "Pages with pricing in the URL?" | `query --filter '[{"field":"properties.path","op":"contains","value":"pricing"}]' --group-by event` | Substring match on properties |
344381
| "How many sessions this week?" | `query --metrics session_count --days 7` | Count distinct sessions |
382+
| "Are there JS errors?" | `events --event '$error'` or `breakdown --property message --event '$error'` | Error log or grouped by message |
345383

346384
For any "how is X doing" question, **always call `insights` first** — it's the single most useful endpoint. For real-time "who's on the site right now", use `live`. For any specific question that the pre-built commands don't directly answer (filtering by country, substring matching, combining multiple filters), use `query`.
347385

@@ -536,7 +574,7 @@ Proactively flag — don't wait to be asked:
536574
- **Spike**: any metric >2× its previous period → "unusual surge, check referrers"
537575
- **Drop**: any metric <50% of previous → "significant decline, worth investigating"
538576
- **Dead project**: zero `page_view` events → "⚠ no traffic detected"
539-
- **Errors**: any `error` events in the window → surface the `message` property
577+
- **Errors**: any `error` or `$error` events in the window → surface the `message` property
540578

541579
### Visualizing results
542580

0 commit comments

Comments
 (0)