Fix fatal error from undefined AjaxTracker::isUserAgentAIBot() method#1381
Fix fatal error from undefined AjaxTracker::isUserAgentAIBot() method#1381jspicher wants to merge 1 commit into
Conversation
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
|
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. I even tried downloading a fresh copy of the files and uploading to our plugins folder but the problem persists. |
|
@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? |
|
Closing due to lack of response. |
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()callsAjaxTracker::isUserAgentAIBot(), but that method doesn't exist in the shippedAjaxTrackeror its parentMatomoTracker. Fresh re-upload of 5.8.0 files didn't help -- the method just isn't there.🐛 Bug Fixes
is_ai_bot_tracking_enabled()/is_tracking_enabled()settings check above theisUserAgentAIBot()call inis_doing_ai_bot_tracking_this_request(). Thetrack_ai_botssetting defaults tofalse, 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.method_exists()guard around theisUserAgentAIBot()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_footerhook ->do_ai_bot_tracking()->is_doing_ai_bot_tracking_this_request()-> crash at line 209. TheAIBotTrackingclass is instantiated unconditionally inWpMatomo.php(no guard on the setting), andregister_hooks()always adds thewp_footeraction. So every frontend page load hits the broken code path.Error:
🔬 Test Plan
📝 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 bundledmatomo-php-trackerlibrary.🔗 Related Issues