Skip to content

Fix fatal error from undefined AjaxTracker::isUserAgentAIBot() method#1381

Closed
jspicher wants to merge 1 commit into
matomo-org:developfrom
jspicher:fix/ai-bot-tracking-undefined-method
Closed

Fix fatal error from undefined AjaxTracker::isUserAgentAIBot() method#1381
jspicher wants to merge 1 commit into
matomo-org:developfrom
jspicher:fix/ai-bot-tracking-undefined-method

Conversation

@jspicher
Copy link
Copy Markdown

@jspicher jspicher commented Mar 31, 2026

Summary

After updating to 5.8.0, our site started returning HTTP 500 on every frontend page. AIBotTracking::is_doing_ai_bot_tracking_this_request() calls AjaxTracker::isUserAgentAIBot(), but that method doesn't exist in the shipped AjaxTracker or its parent MatomoTracker. Fresh re-upload of 5.8.0 files didn't help -- the method just isn't there.

🐛 Bug Fixes

  • Moved the is_ai_bot_tracking_enabled() / is_tracking_enabled() settings check above the isUserAgentAIBot() call in is_doing_ai_bot_tracking_this_request(). The track_ai_bots setting defaults to false, but the old code hit the undefined method before it ever checked the setting, so the fatal error fired even with the feature turned off.
  • Added a method_exists() guard around the isUserAgentAIBot() call. If somebody does enable AI bot tracking but the bundled tracker library still doesn't have the method, the code skips tracking instead of crashing the site.

🔧 Technical details

The call chain is: wp_footer hook -> do_ai_bot_tracking() -> is_doing_ai_bot_tracking_this_request() -> crash at line 209. The AIBotTracking class is instantiated unconditionally in WpMatomo.php (no guard on the setting), and register_hooks() always adds the wp_footer action. So every frontend page load hits the broken code path.

Error:

Fatal error: Uncaught Error: Call to undefined method WpMatomo\AjaxTracker::isUserAgentAIBot()
in classes/WpMatomo/AIBotTracking.php:209

🔬 Test Plan

  • Confirm site no longer returns HTTP 500 on frontend pages
  • Confirm AI bot tracking still works if the method gets added to MatomoTracker in a future update
  • Verify no regressions in standard Matomo tracking

📝 Additional Notes

This is a minimal, non-breaking fix. The settings check was already in the method -- it just needed to run earlier. The method_exists() guard is there as a safety net so this kind of thing can't take down a site again.

The longer-term fix is probably shipping the isUserAgentAIBot() method in the bundled matomo-php-tracker library.

🔗 Related Issues

AIBotTracking::is_doing_ai_bot_tracking_this_request() calls
AjaxTracker::isUserAgentAIBot() which does not exist in the bundled
MatomoTracker library. This causes a fatal error (HTTP 500) on every
frontend page load, even when AI bot tracking is disabled.

Two changes:
- Move the is_ai_bot_tracking_enabled() / is_tracking_enabled() check
  above the isUserAgentAIBot() call so the method returns early when
  the feature is off (which is the default)
- Add a method_exists() guard around isUserAgentAIBot() as a safety
  net for when the feature is enabled but the method is still missing
@diosmosis
Copy link
Copy Markdown
Member

Hi @jspicher, this method does exist in the MatomoTracker shipped with this plugin, see: https://github.com/matomo-org/matomo-for-wordpress/blob/develop/app/vendor/matomo/matomo-php-tracker/MatomoTracker.php#L2075

Are you using another plugin that also includes the matomo-php-tracker?

@jspicher
Copy link
Copy Markdown
Author

Hi @jspicher, this method does exist in the MatomoTracker shipped with this plugin, see: https://github.com/matomo-org/matomo-for-wordpress/blob/develop/app/vendor/matomo/matomo-php-tracker/MatomoTracker.php#L2075

Are you using another plugin that also includes the matomo-php-tracker?

Hello @diosmosis we ran an update through wp-admin and it broke our site because of this.
Matomo Analytics - Ethical Stats. Powerful Insights. Privacy friendly, GDPR compliant and self-hosted. Matomo is the #1 Google Analytics alternative that gives you control of your data. Free and secure.
Version 5.8.0

I even tried downloading a fresh copy of the files and uploading to our plugins folder but the problem persists.

@diosmosis
Copy link
Copy Markdown
Member

@jspicher Hi, can you answer my question: are you using another plugin that also includes the matomo-php-tracker?

Can you check the file I linked above in your server and see if the method is there?

@diosmosis
Copy link
Copy Markdown
Member

Closing due to lack of response.

@diosmosis diosmosis closed this Apr 8, 2026
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.

Fatal error in AIBotTracking.php - undefined method AjaxTracker::isUserAgentAIBot()

2 participants