Skip to content

Comments

Add AI bot classification for event enrichment#76

Open
jaredmixpanel wants to merge 5 commits intomainfrom
feature/ai-bot-classification
Open

Add AI bot classification for event enrichment#76
jaredmixpanel wants to merge 5 commits intomainfrom
feature/ai-bot-classification

Conversation

@jaredmixpanel
Copy link

Summary

Adds AI bot classification with HTTP middleware that automatically detects AI crawler requests and enriches tracked events with classification properties.

What it does

  • Classifies user-agent strings against a database of 12 known AI bots
  • Enriches events with $is_ai_bot, $ai_bot_name, $ai_bot_provider, and $ai_bot_category properties
  • Supports custom bot patterns that take priority over built-in patterns
  • Case-insensitive matching

AI Bots Detected

GPTBot, ChatGPT-User, OAI-SearchBot, ClaudeBot, Claude-User, Google-Extended, PerplexityBot, Bytespider, CCBot, Applebot-Extended, Meta-ExternalAgent, cohere-ai

Files Added

  • ai_bot_classifier.go
  • ai_bot_classifier_test.go
  • ai_bot_middleware.go
  • ai_bot_middleware_test.go

Files Modified

  • ingestion.go
  • mixpanel.go

Test Plan

  • All 12 AI bot user-agents correctly classified
  • Non-AI-bot user-agents return $is_ai_bot: false (Chrome, Googlebot, curl, etc.)
  • Empty string and null/nil inputs handled gracefully
  • Case-insensitive matching works
  • Custom bot patterns checked before built-in
  • Event properties preserved through enrichment
  • No regressions in existing test suite

Part of AI bot classification feature for Go SDK.
Part of AI bot classification feature for Go SDK.
Part of AI bot classification feature for Go SDK.
Fix golangci errcheck lint failure.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds AI bot detection to the Mixpanel Go client so HTTP requests and/or Track() calls can classify known AI crawlers by User-Agent and enrich events with standardized bot metadata.

Changes:

  • Introduces an AI bot user-agent classifier with a built-in database and optional custom overrides.
  • Adds HTTP middleware + helper utilities to store bot classification in request context and to copy request UA/IP into events.
  • Adds optional automatic event enrichment on ApiClient.Track() via new client options.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
ai_bot_classifier.go Adds classifier types, built-in bot database, and classification helpers.
ai_bot_classifier_test.go Adds unit tests for built-in detection, negative cases, and custom overrides.
ai_bot_middleware.go Adds BotClassifyingIngestion, HTTP middleware, and TrackRequest helper.
ai_bot_middleware_test.go Adds tests for ingestion wrapper enrichment, middleware context behavior, and TrackRequest.
ingestion.go Enriches ApiClient.Track() events with bot classification when enabled via options.
mixpanel.go Adds botClassifier to ApiClient and new options to enable classification.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Add nil receiver guard in Classify()
- Default nil classifier to built-in in constructor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant