chore: Remove CTA A/B Testing legacy system
This feature was not part of the current development phase. Deleted files: - Inc/cta-ab-testing.php (A/B testing implementation) - Inc/customizer-cta.php (WordPress Customizer settings + Google Analytics) - TemplateParts/content-cta.php (CTA template part) - Assets/Js/cta-tracking.js (GA4 tracking script) Modified files: - functions.php: Remove require_once for deleted files - functions-addon.php: Remove CTA loading references - Inc/enqueue-scripts.php: Remove roi_enqueue_cta_assets() function Note: CTA components in Admin Panel (CtaBoxSidebar, CtaLetsTalk, CtaPost) are NOT affected - they are part of the Clean Architecture system. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,213 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* CTA A/B Testing System
|
||||
*
|
||||
* Sistema de Call-to-Action con A/B Testing que muestra aleatoriamente
|
||||
* una de dos variantes (A o B) para optimizar conversiones.
|
||||
*
|
||||
* Características:
|
||||
* - Rotación 50/50 entre variante A (Catálogo) y B (Membresía)
|
||||
* - Cookie persistence para mantener la misma variante por usuario
|
||||
* - Template tag: roi_display_cta()
|
||||
* - Tracking de conversiones con Google Analytics 4
|
||||
*
|
||||
* @package ROI_Theme
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtener la variante de CTA para el usuario actual
|
||||
*
|
||||
* Usa cookies para mantener la misma variante durante 30 días.
|
||||
* Si no hay cookie, asigna aleatoriamente A o B (50/50).
|
||||
*
|
||||
* @return string 'A' o 'B'
|
||||
*/
|
||||
function roi_get_cta_variant() {
|
||||
$cookie_name = 'roi_cta_variant';
|
||||
|
||||
// Verificar si ya existe una variante asignada
|
||||
if (isset($_COOKIE[$cookie_name]) && in_array($_COOKIE[$cookie_name], array('A', 'B'))) {
|
||||
return sanitize_text_field($_COOKIE[$cookie_name]);
|
||||
}
|
||||
|
||||
// Asignar variante aleatoria (50/50)
|
||||
$variant = (rand(0, 1) === 0) ? 'A' : 'B';
|
||||
|
||||
// Guardar en cookie por 30 días
|
||||
setcookie($cookie_name, $variant, time() + (30 * DAY_IN_SECONDS), COOKIEPATH, COOKIE_DOMAIN);
|
||||
|
||||
return $variant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Template tag para mostrar el CTA
|
||||
*
|
||||
* Uso: <?php roi_display_cta(); ?>
|
||||
*
|
||||
* @param array $args Argumentos opcionales para personalizar el CTA
|
||||
* @return void
|
||||
*/
|
||||
function roi_display_cta($args = array()) {
|
||||
// Verificar si el CTA está habilitado
|
||||
$enable_cta = get_theme_mod('roi_enable_cta', true);
|
||||
if (!$enable_cta) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Solo mostrar en posts individuales por defecto
|
||||
$show_on = isset($args['show_on']) ? $args['show_on'] : 'single';
|
||||
|
||||
if ($show_on === 'single' && !is_single()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Obtener la variante del usuario
|
||||
$variant = roi_get_cta_variant();
|
||||
|
||||
// Obtener configuración desde el Customizer
|
||||
$cta_config = roi_get_cta_config($variant);
|
||||
|
||||
// Renderizar el CTA
|
||||
roi_render_cta($variant, $cta_config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtener configuración del CTA desde el Customizer
|
||||
*
|
||||
* @param string $variant 'A' o 'B'
|
||||
* @return array Configuración del CTA
|
||||
*/
|
||||
function roi_get_cta_config($variant) {
|
||||
if ($variant === 'A') {
|
||||
return array(
|
||||
'title' => get_theme_mod('roi_cta_a_title', __('Accede a 200,000+ Análisis de Precios Unitarios', 'roi-theme')),
|
||||
'text' => get_theme_mod('roi_cta_a_text', __('Consulta estructuras completas, insumos y dosificaciones de los APUs más utilizados en construcción en México.', 'roi-theme')),
|
||||
'button_text' => get_theme_mod('roi_cta_a_button', __('Ver Catálogo Completo', 'roi-theme')),
|
||||
'button_url' => get_theme_mod('roi_cta_a_url', home_url('/catalogo')),
|
||||
'variant' => 'A',
|
||||
);
|
||||
} else {
|
||||
return array(
|
||||
'title' => get_theme_mod('roi_cta_b_title', __('¿Necesitas Consultar Más APUs?', 'roi-theme')),
|
||||
'text' => get_theme_mod('roi_cta_b_text', __('Accede a nuestra biblioteca de 200,000 análisis de precios unitarios con estructuras detalladas y listados de insumos.', 'roi-theme')),
|
||||
'button_text' => get_theme_mod('roi_cta_b_button', __('Conocer Planes de Membresía', 'roi-theme')),
|
||||
'button_url' => get_theme_mod('roi_cta_b_url', home_url('/planes')),
|
||||
'variant' => 'B',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renderizar el HTML del CTA
|
||||
*
|
||||
* @param string $variant 'A' o 'B'
|
||||
* @param array $config Configuración del CTA
|
||||
* @return void
|
||||
*/
|
||||
function roi_render_cta($variant, $config) {
|
||||
?>
|
||||
<!-- CTA A/B Testing - Variante <?php echo esc_attr($variant); ?> -->
|
||||
<div class="my-5 p-4 rounded cta-section cta-variant-<?php echo esc_attr(strtolower($variant)); ?>"
|
||||
data-variant="<?php echo esc_attr($variant); ?>">
|
||||
<div class="row align-items-center">
|
||||
<div class="col-md-8">
|
||||
<h3 class="h4 fw-bold text-white mb-2">
|
||||
<?php echo esc_html($config['title']); ?>
|
||||
</h3>
|
||||
<p class="text-white mb-md-0">
|
||||
<?php echo esc_html($config['text']); ?>
|
||||
</p>
|
||||
</div>
|
||||
<div class="col-md-4 text-md-end mt-3 mt-md-0">
|
||||
<a href="<?php echo esc_url($config['button_url']); ?>"
|
||||
class="btn btn-light btn-lg cta-button"
|
||||
data-cta-variant="<?php echo esc_attr($variant); ?>">
|
||||
<?php echo esc_html($config['button_text']); ?>
|
||||
<i class="bi bi-arrow-right ms-2"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook para agregar el CTA automáticamente después del contenido
|
||||
*
|
||||
* Se puede desactivar usando remove_filter('the_content', 'roi_auto_insert_cta')
|
||||
*/
|
||||
function roi_auto_insert_cta($content) {
|
||||
// Solo en posts individuales
|
||||
if (!is_single()) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
// Verificar si está habilitado
|
||||
$enable_cta = get_theme_mod('roi_enable_cta', true);
|
||||
$auto_insert = get_theme_mod('roi_cta_auto_insert', false);
|
||||
|
||||
if (!$enable_cta || !$auto_insert) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
// Capturar el output del CTA
|
||||
ob_start();
|
||||
roi_display_cta();
|
||||
$cta_html = ob_get_clean();
|
||||
|
||||
// Insertar después del contenido
|
||||
return $content . $cta_html;
|
||||
}
|
||||
// add_filter('the_content', 'roi_auto_insert_cta', 20); // Descomentado por defecto, usar template tag
|
||||
|
||||
/**
|
||||
* Shortcode para insertar el CTA manualmente
|
||||
*
|
||||
* Uso: [roi_cta]
|
||||
*/
|
||||
function roi_cta_shortcode($atts) {
|
||||
ob_start();
|
||||
roi_display_cta($atts);
|
||||
return ob_get_clean();
|
||||
}
|
||||
add_shortcode('roi_cta', 'roi_cta_shortcode');
|
||||
|
||||
/**
|
||||
* Agregar atributos data-* al body para tracking
|
||||
*/
|
||||
function roi_add_cta_body_class($classes) {
|
||||
if (is_single() && get_theme_mod('roi_enable_cta', true)) {
|
||||
$variant = roi_get_cta_variant();
|
||||
$classes[] = 'has-cta';
|
||||
$classes[] = 'cta-variant-' . strtolower($variant);
|
||||
}
|
||||
return $classes;
|
||||
}
|
||||
add_filter('body_class', 'roi_add_cta_body_class');
|
||||
|
||||
/**
|
||||
* Agregar datos de configuración para JavaScript
|
||||
*/
|
||||
function roi_cta_localize_script() {
|
||||
if (!is_single() || !get_theme_mod('roi_enable_cta', true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$variant = roi_get_cta_variant();
|
||||
|
||||
$cta_data = array(
|
||||
'variant' => $variant,
|
||||
'ga_enabled' => !empty(get_theme_mod('roi_ga_tracking_id', '')),
|
||||
'ga_id' => get_theme_mod('roi_ga_tracking_id', ''),
|
||||
'debug_mode' => defined('WP_DEBUG') && WP_DEBUG,
|
||||
);
|
||||
|
||||
wp_localize_script('roicta-tracking', 'rroiA', $cta_data);
|
||||
}
|
||||
add_action('wp_enqueue_scripts', 'roi_cta_localize_script', 20);
|
||||
@@ -1,257 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* CTA A/B Testing Customizer Settings
|
||||
*
|
||||
* Opciones del panel de personalización para configurar
|
||||
* las dos variantes del CTA (A y B).
|
||||
*
|
||||
* @package ROI_Theme
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registrar configuraciones del CTA en el Customizer
|
||||
*/
|
||||
function roi_customize_cta($wp_customize) {
|
||||
// Agregar sección para CTA A/B Testing
|
||||
$wp_customize->add_section('roi_cta', array(
|
||||
'title' => __('CTA A/B Testing', 'roi-theme'),
|
||||
'description' => __('Configura las dos variantes del Call-to-Action que se mostrarán aleatoriamente. El sistema asignará automáticamente una variante a cada usuario (50/50).', 'roi-theme'),
|
||||
'priority' => 132,
|
||||
));
|
||||
|
||||
// =====================================================
|
||||
// CONFIGURACIÓN GENERAL
|
||||
// =====================================================
|
||||
|
||||
// Habilitar/Deshabilitar CTA
|
||||
$wp_customize->add_setting('roi_enable_cta', array(
|
||||
'default' => true,
|
||||
'sanitize_callback' => 'roi_sanitize_checkbox',
|
||||
'transport' => 'refresh',
|
||||
));
|
||||
$wp_customize->add_control('roi_enable_cta', array(
|
||||
'label' => __('Habilitar CTA con A/B Testing', 'roi-theme'),
|
||||
'description' => __('Muestra un Call-to-Action en los posts individuales con dos variantes aleatorias.', 'roi-theme'),
|
||||
'section' => 'roi_cta',
|
||||
'type' => 'checkbox',
|
||||
));
|
||||
|
||||
// Auto-insertar CTA (opcional, por defecto usar template tag)
|
||||
$wp_customize->add_setting('roi_cta_auto_insert', array(
|
||||
'default' => false,
|
||||
'sanitize_callback' => 'roi_sanitize_checkbox',
|
||||
'transport' => 'refresh',
|
||||
));
|
||||
$wp_customize->add_control('roi_cta_auto_insert', array(
|
||||
'label' => __('Auto-insertar CTA después del contenido', 'roi-theme'),
|
||||
'description' => __('Si está desactivado, usa el template tag roi_display_cta() manualmente.', 'roi-theme'),
|
||||
'section' => 'roi_cta',
|
||||
'type' => 'checkbox',
|
||||
));
|
||||
|
||||
// =====================================================
|
||||
// VARIANTE A - ENFOQUE EN CATÁLOGO
|
||||
// =====================================================
|
||||
|
||||
// Separador visual
|
||||
$wp_customize->add_setting('roi_cta_a_separator', array(
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
));
|
||||
$wp_customize->add_control(new WP_Customize_Control(
|
||||
$wp_customize,
|
||||
'roi_cta_a_separator',
|
||||
array(
|
||||
'label' => __('━━━ Variante A: Catálogo ━━━', 'roi-theme'),
|
||||
'description' => __('Enfoque en acceso al catálogo de 200,000+ APUs', 'roi-theme'),
|
||||
'section' => 'roi_cta',
|
||||
'type' => 'hidden',
|
||||
)
|
||||
));
|
||||
|
||||
// Título Variante A
|
||||
$wp_customize->add_setting('roi_cta_a_title', array(
|
||||
'default' => __('Accede a 200,000+ Análisis de Precios Unitarios', 'roi-theme'),
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
'transport' => 'postMessage',
|
||||
));
|
||||
$wp_customize->add_control('roi_cta_a_title', array(
|
||||
'label' => __('Título', 'roi-theme'),
|
||||
'section' => 'roi_cta',
|
||||
'type' => 'text',
|
||||
));
|
||||
|
||||
// Texto Variante A
|
||||
$wp_customize->add_setting('roi_cta_a_text', array(
|
||||
'default' => __('Consulta estructuras completas, insumos y dosificaciones de los APUs más utilizados en construcción en México.', 'roi-theme'),
|
||||
'sanitize_callback' => 'sanitize_textarea_field',
|
||||
'transport' => 'postMessage',
|
||||
));
|
||||
$wp_customize->add_control('roi_cta_a_text', array(
|
||||
'label' => __('Texto descriptivo', 'roi-theme'),
|
||||
'section' => 'roi_cta',
|
||||
'type' => 'textarea',
|
||||
));
|
||||
|
||||
// Botón Variante A
|
||||
$wp_customize->add_setting('roi_cta_a_button', array(
|
||||
'default' => __('Ver Catálogo Completo', 'roi-theme'),
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
'transport' => 'postMessage',
|
||||
));
|
||||
$wp_customize->add_control('roi_cta_a_button', array(
|
||||
'label' => __('Texto del botón', 'roi-theme'),
|
||||
'section' => 'roi_cta',
|
||||
'type' => 'text',
|
||||
));
|
||||
|
||||
// URL Variante A
|
||||
$wp_customize->add_setting('roi_cta_a_url', array(
|
||||
'default' => '#',
|
||||
'sanitize_callback' => 'esc_url_raw',
|
||||
'transport' => 'postMessage',
|
||||
));
|
||||
$wp_customize->add_control('roi_cta_a_url', array(
|
||||
'label' => __('URL del botón', 'roi-theme'),
|
||||
'description' => __('Ejemplo: /catalogo-completo/ o una URL completa', 'roi-theme'),
|
||||
'section' => 'roi_cta',
|
||||
'type' => 'url',
|
||||
));
|
||||
|
||||
// =====================================================
|
||||
// VARIANTE B - ENFOQUE EN MEMBRESÍA
|
||||
// =====================================================
|
||||
|
||||
// Separador visual
|
||||
$wp_customize->add_setting('roi_cta_b_separator', array(
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
));
|
||||
$wp_customize->add_control(new WP_Customize_Control(
|
||||
$wp_customize,
|
||||
'roi_cta_b_separator',
|
||||
array(
|
||||
'label' => __('━━━ Variante B: Membresía ━━━', 'roi-theme'),
|
||||
'description' => __('Enfoque en planes de membresía y acceso premium', 'roi-theme'),
|
||||
'section' => 'roi_cta',
|
||||
'type' => 'hidden',
|
||||
)
|
||||
));
|
||||
|
||||
// Título Variante B
|
||||
$wp_customize->add_setting('roi_cta_b_title', array(
|
||||
'default' => __('¿Necesitas Consultar Más APUs?', 'roi-theme'),
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
'transport' => 'postMessage',
|
||||
));
|
||||
$wp_customize->add_control('roi_cta_b_title', array(
|
||||
'label' => __('Título', 'roi-theme'),
|
||||
'section' => 'roi_cta',
|
||||
'type' => 'text',
|
||||
));
|
||||
|
||||
// Texto Variante B
|
||||
$wp_customize->add_setting('roi_cta_b_text', array(
|
||||
'default' => __('Accede a nuestra biblioteca de 200,000 análisis de precios unitarios con estructuras detalladas y listados de insumos.', 'roi-theme'),
|
||||
'sanitize_callback' => 'sanitize_textarea_field',
|
||||
'transport' => 'postMessage',
|
||||
));
|
||||
$wp_customize->add_control('roi_cta_b_text', array(
|
||||
'label' => __('Texto descriptivo', 'roi-theme'),
|
||||
'section' => 'roi_cta',
|
||||
'type' => 'textarea',
|
||||
));
|
||||
|
||||
// Botón Variante B
|
||||
$wp_customize->add_setting('roi_cta_b_button', array(
|
||||
'default' => __('Conocer Planes de Membresía', 'roi-theme'),
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
'transport' => 'postMessage',
|
||||
));
|
||||
$wp_customize->add_control('roi_cta_b_button', array(
|
||||
'label' => __('Texto del botón', 'roi-theme'),
|
||||
'section' => 'roi_cta',
|
||||
'type' => 'text',
|
||||
));
|
||||
|
||||
// URL Variante B
|
||||
$wp_customize->add_setting('roi_cta_b_url', array(
|
||||
'default' => '#',
|
||||
'sanitize_callback' => 'esc_url_raw',
|
||||
'transport' => 'postMessage',
|
||||
));
|
||||
$wp_customize->add_control('roi_cta_b_url', array(
|
||||
'label' => __('URL del botón', 'roi-theme'),
|
||||
'description' => __('Ejemplo: /planes-de-membresia/ o una URL completa', 'roi-theme'),
|
||||
'section' => 'roi_cta',
|
||||
'type' => 'url',
|
||||
));
|
||||
|
||||
// =====================================================
|
||||
// GOOGLE ANALYTICS TRACKING
|
||||
// =====================================================
|
||||
|
||||
// Separador visual
|
||||
$wp_customize->add_setting('roi_cta_ga_separator', array(
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
));
|
||||
$wp_customize->add_control(new WP_Customize_Control(
|
||||
$wp_customize,
|
||||
'roi_cta_ga_separator',
|
||||
array(
|
||||
'label' => __('━━━ Google Analytics ━━━', 'roi-theme'),
|
||||
'description' => __('Configuración para tracking de conversiones', 'roi-theme'),
|
||||
'section' => 'roi_cta',
|
||||
'type' => 'hidden',
|
||||
)
|
||||
));
|
||||
|
||||
// Google Analytics Tracking ID
|
||||
$wp_customize->add_setting('roi_ga_tracking_id', array(
|
||||
'default' => '',
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
'transport' => 'refresh',
|
||||
));
|
||||
$wp_customize->add_control('roi_ga_tracking_id', array(
|
||||
'label' => __('Google Analytics Tracking ID', 'roi-theme'),
|
||||
'description' => __('Formato: G-XXXXXXXXXX (GA4) o UA-XXXXXXXXX-X (Universal Analytics). Déjalo vacío si ya tienes GA instalado mediante plugin.', 'roi-theme'),
|
||||
'section' => 'roi_cta',
|
||||
'type' => 'text',
|
||||
));
|
||||
}
|
||||
add_action('customize_register', 'roi_customize_cta');
|
||||
|
||||
/**
|
||||
* Agregar script de Google Analytics en el header si está configurado
|
||||
*/
|
||||
function roi_output_google_analytics() {
|
||||
$tracking_id = get_theme_mod('roi_ga_tracking_id', '');
|
||||
|
||||
// No mostrar si está vacío o si estamos en el admin
|
||||
if (empty($tracking_id) || is_admin()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// No mostrar si es un usuario admin logueado
|
||||
if (current_user_can('manage_options')) {
|
||||
return;
|
||||
}
|
||||
?>
|
||||
<!-- Google Analytics (CTA A/B Testing) -->
|
||||
<script async src="https://www.googletagmanager.com/gtag/js?id=<?php echo esc_attr($tracking_id); ?>"></script>
|
||||
<script>
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag(){dataLayer.push(arguments);}
|
||||
gtag('js', new Date());
|
||||
gtag('config', '<?php echo esc_js($tracking_id); ?>', {
|
||||
'anonymize_ip': true,
|
||||
'cookie_flags': 'SameSite=None;Secure'
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
add_action('wp_head', 'roi_output_google_analytics', 1);
|
||||
@@ -505,45 +505,6 @@ function roi_enqueue_apu_tables_autoclass_script() {
|
||||
|
||||
add_action('wp_enqueue_scripts', 'roi_enqueue_apu_tables_autoclass_script', 15);
|
||||
|
||||
/**
|
||||
* Enqueue CTA A/B Testing styles and scripts
|
||||
*/
|
||||
function roi_enqueue_cta_assets() {
|
||||
// Solo enqueue en posts individuales
|
||||
if (!is_single()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Verificar si el CTA está habilitado
|
||||
$enable_cta = get_theme_mod('roi_enable_cta', true);
|
||||
if (!$enable_cta) {
|
||||
return;
|
||||
}
|
||||
|
||||
// CTA CSS
|
||||
wp_enqueue_style(
|
||||
'roi-cta-style',
|
||||
get_template_directory_uri() . '/Assets/css/componente-cta-ab-testing.css',
|
||||
array('roi-bootstrap'),
|
||||
ROI_VERSION,
|
||||
'all'
|
||||
);
|
||||
|
||||
// CTA Tracking JS
|
||||
wp_enqueue_script(
|
||||
'roi-cta-tracking',
|
||||
get_template_directory_uri() . '/Assets/js/cta-tracking.js',
|
||||
array(),
|
||||
ROI_VERSION,
|
||||
array(
|
||||
'in_footer' => true,
|
||||
'strategy' => 'defer',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
add_action('wp_enqueue_scripts', 'roi_enqueue_cta_assets', 16);
|
||||
|
||||
/**
|
||||
* Enqueue CTA Box Sidebar styles (Issue #36)
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user