feat(admin): Add Google AdSense Auto Ads support to theme-settings
- Add adsense group to theme-settings.json schema (v1.2.0) - Add adsense_publisher_id and adsense_auto_ads fields - Add AdSense card UI in ThemeSettingsFormBuilder - Add field mappings in ThemeSettingsFieldMapper - Add renderAdSenseAutoAds() method in ThemeSettingsRenderer - Inject AdSense script in wp_head when configured 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,7 @@ use ROITheme\Shared\Domain\Entities\Component;
|
||||
*
|
||||
* Responsabilidades:
|
||||
* - Generar script de Google Analytics
|
||||
* - Generar script de Google AdSense Auto Ads
|
||||
* - Generar CSS personalizado
|
||||
* - Generar JavaScript para header
|
||||
* - Generar JavaScript para footer
|
||||
@@ -54,6 +55,7 @@ final class ThemeSettingsRenderer implements RendererInterface
|
||||
*
|
||||
* Incluye:
|
||||
* - Google Analytics script (si configurado)
|
||||
* - Google AdSense Auto Ads script (si configurado)
|
||||
* - Custom CSS (si configurado)
|
||||
* - Custom JS Header (si configurado)
|
||||
*
|
||||
@@ -75,6 +77,12 @@ final class ThemeSettingsRenderer implements RendererInterface
|
||||
$output .= $gaOutput . "\n";
|
||||
}
|
||||
|
||||
// Google AdSense Auto Ads
|
||||
$adsenseOutput = $this->renderAdSenseAutoAds($data);
|
||||
if (!empty($adsenseOutput)) {
|
||||
$output .= $adsenseOutput . "\n";
|
||||
}
|
||||
|
||||
// Custom CSS
|
||||
$cssOutput = $this->renderCustomCSS($data);
|
||||
if (!empty($cssOutput)) {
|
||||
@@ -237,6 +245,34 @@ ga("send", "pageview");
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Genera el script de Google AdSense Auto Ads
|
||||
*
|
||||
* @param array $data Datos del componente
|
||||
* @return string Script de AdSense o vacio si no configurado
|
||||
*/
|
||||
private function renderAdSenseAutoAds(array $data): string
|
||||
{
|
||||
$publisherId = trim($data['adsense']['adsense_publisher_id'] ?? '');
|
||||
$autoAdsEnabled = ($data['adsense']['adsense_auto_ads'] ?? false) === true;
|
||||
|
||||
// Solo mostrar si tiene publisher ID y auto ads esta activado
|
||||
if (empty($publisherId) || !$autoAdsEnabled) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Validar formato del publisher ID (ca-pub-XXXXXXXXXX)
|
||||
if (!preg_match('/^ca-pub-\d+$/', $publisherId)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
'<!-- Google AdSense Auto Ads (ROI Theme) -->
|
||||
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=%s" crossorigin="anonymous"></script>',
|
||||
esc_attr($publisherId)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Genera el CSS personalizado
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user