| ';
if ( $test ) {
$body .= ' TEST MESSAGE — sent by an administrator to verify delivery. ';
}
$body .= 'Reporting period ' . esc_html( $period ) . ' ';
$body .= 'AI bot / fetch requests';
$body .= '';
$stats = array(
array( 'Total bot / fetch requests', (int) ( $traffic['crawler_hits'] ?? 0 ) ),
array( 'Delivered responses (2xx or legacy unknown)', (int) ( $traffic['crawler_successful'] ?? 0 ) ),
array( 'Verified bot requests', (int) ( $traffic['crawler_verified'] ?? 0 ) ),
array( 'AI-referred visits', (int) ( $traffic['referral_hits'] ?? 0 ) ),
array( 'Guidance-file requests', (int) ( $traffic['guidance_hits'] ?? 0 ) ),
);
foreach ( $stats as $stat ) {
$body .= '| ' . esc_html( $stat[0] ) . ' | ';
$body .= '' . esc_html( number_format_i18n( $stat[1] ) ) . ' | ';
}
$body .= ' ';
$body .= 'Delivered includes 2xx and legacy records with unknown status. Verified requires positive identity checks; unverified does not necessarily mean fake. Counts are requests, not unique users. ';
$detail = AI_O_Optimiser_Email_Report::traffic_details( $traffic );
$groups = array(
'bots' => array( 'title' => 'Top AI bots and fetchers', 'unit' => 'Requests' ),
'pages' => array( 'title' => 'Most-fetched pages by AI bots', 'unit' => 'Requests' ),
'referrers' => array( 'title' => 'AI referral sources', 'unit' => 'Visits' ),
'guidance' => array( 'title' => 'Guidance-file requests', 'unit' => 'Requests' ),
);
foreach ( $groups as $key => $group ) {
$body .= '' . esc_html( $group['title'] ) . '';
$body .= '';
if ( ! $detail[ $key ] ) {
$body .= '| No matching activity recorded in this period. | ';
}
foreach ( $detail[ $key ] as $row ) {
$subtitle = '' !== $row['last_seen'] ? 'Last seen ' . esc_html( $row['last_seen'] ) . ' UTC' : '';
$body .= '| ' . esc_html( $row['label'] ) . $subtitle . ' | ';
$body .= '' . esc_html( number_format_i18n( $row['count'] ) ) . ' | ';
}
$body .= ' ';
}
$body .= 'View full Activity Report → ';
$body .= 'Sign in to WordPress to view the full report. A PDF summary is attached only when you enable that option. ';
$body .= ' |
';
$body .= '