diff --git a/.claude/settings.local.json b/.claude/settings.local.json index 6051fbda..77b7f9a2 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -3,7 +3,8 @@ "allow": [ "Bash(mkdir:*)", "mcp__serena__activate_project", - "mcp__serena__find_symbol" + "mcp__serena__find_symbol", + "Bash(ssh:*)" ] } } diff --git a/Public/AdsensePlacement/Infrastructure/Services/ContentAdInjector.php b/Public/AdsensePlacement/Infrastructure/Services/ContentAdInjector.php index 6a614e9c..1df19e30 100644 --- a/Public/AdsensePlacement/Infrastructure/Services/ContentAdInjector.php +++ b/Public/AdsensePlacement/Infrastructure/Services/ContentAdInjector.php @@ -120,6 +120,7 @@ final class ContentAdInjector private function injectAdvanced(string $content): string { $config = $this->settings['incontent_advanced'] ?? []; + $debugSteps = []; // DEBUG // Obtener configuracion $maxAds = (int)($config['incontent_max_total_ads'] ?? 8); @@ -127,26 +128,31 @@ final class ContentAdInjector $priorityMode = $config['incontent_priority_mode'] ?? 'position'; $format = $config['incontent_format'] ?? 'in-article'; + $debugSteps['config'] = "maxAds=$maxAds, minSpacing=$minSpacing, priority=$priorityMode"; // DEBUG + // PASO 1: Escanear contenido para encontrar todas las ubicaciones $locations = $this->scanContent($content); + $debugSteps['step1_scan'] = count($locations); // DEBUG if (empty($locations)) { - return $content; + return '' . $content; } // PASO 2: Filtrar por configuracion (enabled) $locations = $this->filterByEnabled($locations, $config); + $debugSteps['step2_enabled'] = count($locations); // DEBUG if (empty($locations)) { - return $content; + return '' . $content; } // PASO 3: Aplicar probabilidad deterministica $postId = get_the_ID() ?: 0; $locations = $this->applyProbability($locations, $config, $postId); + $debugSteps['step3_probability'] = count($locations); // DEBUG if (empty($locations)) { - return $content; + return '' . $content; } // PASO 4-5: Filtrar por espaciado y limite (segun priority_mode) @@ -155,13 +161,18 @@ final class ContentAdInjector } else { $locations = $this->filterByPositionFirst($locations, $minSpacing, $maxAds); } + $debugSteps['step4_spacing'] = count($locations); // DEBUG if (empty($locations)) { - return $content; + return '' . $content; } // Ordenar por posicion para insercion correcta usort($locations, fn($a, $b) => $a['position'] <=> $b['position']); + $debugSteps['final_ads'] = count($locations); // DEBUG + + // Insertar debug comment + $content = '' . $content; // PASO 6: Insertar anuncios return $this->insertAds($content, $locations, $format);