Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions classes/WpMatomo/AIBotTracking.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,15 @@ private function is_doing_ai_bot_tracking_this_request() {
return true;
}

// Check settings early to avoid calling methods that may not exist
// in the bundled MatomoTracker library (e.g. isUserAgentAIBot).
if (
! $this->settings->is_ai_bot_tracking_enabled()
|| ! $this->settings->is_tracking_enabled()
) {
return false;
}

if ( ! $this->should_track_current_page() ) {
return false;
}
Expand All @@ -206,13 +215,8 @@ private function is_doing_ai_bot_tracking_this_request() {
$tracker = $this->get_tracker();

// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
if ( ! AjaxTracker::isUserAgentAIBot( $tracker->userAgent ) ) {
return false;
}

if (
! $this->settings->is_ai_bot_tracking_enabled()
|| ! $this->settings->is_tracking_enabled()
if ( ! method_exists( AjaxTracker::class, 'isUserAgentAIBot' )
|| ! AjaxTracker::isUserAgentAIBot( $tracker->userAgent )
) {
return false;
}
Expand Down