Skip to content

Add method to track an AI bot request, if the current user agent is a known AI bot - #148

Merged
sgiehl merged 14 commits into
masterfrom
track-if-ai
Jul 24, 2026
Merged

Add method to track an AI bot request, if the current user agent is a known AI bot#148
sgiehl merged 14 commits into
masterfrom
track-if-ai

Conversation

@diosmosis

Copy link
Copy Markdown
Member

Description

Changes:

  • Add doTrackPageViewIfAIBot & getUrlTrackAIBot methods for sending AI bot tracking requests server side.
  • Add isUserAgentAIBot static method for checking if a user agent matches a known AI bot.

Checklist

  • [✔/✖/NA] I have understood, reviewed, and tested all AI outputs before use
  • [✔/✖/NA] All AI instructions respect security, IP, and privacy rules

Review

@diosmosis
diosmosis marked this pull request as draft December 12, 2025 06:58
@diosmosis
diosmosis marked this pull request as ready for review February 3, 2026 04:57
@diosmosis
diosmosis requested a review from a team February 3, 2026 05:04
Comment thread MatomoTracker.php Outdated
Comment thread MatomoTracker.php Outdated
Co-authored-by: Thomas ZILLIOX <thomas@zilliox.me>
@diosmosis

Copy link
Copy Markdown
Member Author

@matomo-org/core-reviewers please review this.

@matomo-org matomo-org deleted a comment from astehlik Jul 19, 2026
@matomo-org matomo-org deleted a comment from astehlik Jul 20, 2026

@sgiehl sgiehl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

AI bot tracking review

Reviewed the branch against what Matomo core (core/Tracker.php) and the BotTracking plugin actually read/expect (cross-checked with two independent passes + the server's own integration tests and BotDetector).

What matches correctly: the recMode=1 semantics (bot-only recording), and the http_status / bw_bytes / pf_srv / source parameter names — all four are read by BotRequestProcessor, and source is genuinely supported (used by VisitorGenerator). 6 of the 7 UA substrings match BotDetector's AI-chatbot patterns exactly.

Blocking / should-fix before merge:

  1. Blocker — the unit suite is red: the Devin row still expects true after Devin was removed from the list (inline).
  2. MajorGPTBot is in the client list but the server's BotDetector doesn't recognize it, so those requests are accepted but recorded nowhere (silent data loss) (inline).

Minor (worth doing in the same pass, both cause silent data loss): !empty() drops valid 0 telemetry, and source isn't truncated to the server's VARCHAR(50) (inline). Plus PHPDoc/return-contract fixes (inline).

Not inlined (low priority):

  • No test exercises doTrackPageViewIfAIBot() itself (matched + unmatched paths), no zero-value boundary test, and there's no positive Google-NotebookLM case in the provider.
  • Unrelated indentation churn at lines ~922, ~1427, ~2022 (formatter over-indentation of continuation params) — revert to keep the diff focused.

Inline comments include ready-to-apply suggestions.

Comment thread MatomoTracker.php Outdated
Comment thread tests/Unit/MatomoTrackerTest.php Outdated
Comment thread tests/Unit/MatomoTrackerTest.php Outdated
Comment thread MatomoTracker.php Outdated
Comment thread MatomoTracker.php
Comment thread MatomoTracker.php Outdated
Co-authored-by: Stefan Giehl <stefan@matomo.org>
@sgiehl
sgiehl merged commit f2afbb8 into master Jul 24, 2026
28 checks passed
@sgiehl
sgiehl deleted the track-if-ai branch July 27, 2026 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants