Files
feadulta/wordpress/wp-content/mu-plugins/fea-analytics.php
rafa 863a3c6677 feat(analytics): GA4 (gtag) + banner de consentimiento de cookies (#93)
- fea-analytics.php: GA4 G-6RT9ZRS4LW vía gtag en mu-plugin (Consent Mode v2,
  default denied). Measurement ID portable: cutover wp-nuevo -> www indoloro.
- fea-cookie-consent.php: banner RGPD discreto, multiidioma ES/EN/FR/IT/PT,
  enlace a la politica resuelto por idioma (Polylang). Aceptar -> consent update.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-19 11:49:59 -04:00

41 lines
1.6 KiB
PHP

<?php
/**
* Plugin Name: Fea Analytics — GA4 (#93)
* Description: Inserta Google Analytics 4 (gtag.js) en el <head> del front-end.
* Measurement ID portable: el cutover wp-nuevo.feadulta.com -> www.feadulta.com
* no requiere tocar nada (el ID no cambia; la Stream URL es informativa).
* NO se filtra tráfico interno (decisión Rafa: las IPs propias cuentan).
* Nota RGPD: GA4 setea cookies; si se añade banner de consentimiento habrá
* que condicionar este tag (Consent Mode) — pendiente, no implementado aquí.
*/
if (!defined('ABSPATH')) exit;
define('FEA_GA4_MEASUREMENT_ID', 'G-6RT9ZRS4LW');
add_action('wp_head', function () {
// wp_head no corre en wp-admin; guard extra por seguridad.
if (is_admin()) return;
$gid = FEA_GA4_MEASUREMENT_ID;
?>
<!-- Google tag (gtag.js) - GA4 #93 -->
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
// Consent Mode v2: por defecto DENEGADO hasta que el usuario acepte en el
// banner (fea-cookie-consent.php hace el consent 'update'). HTML idéntico
// para todos (cacheable por Cloudflare); el estado por usuario lo aplica el
// banner en JS leyendo la cookie.
gtag('consent', 'default', {
'ad_storage': 'denied',
'ad_user_data': 'denied',
'ad_personalization': 'denied',
'analytics_storage': 'denied',
'wait_for_update': 500
});
gtag('js', new Date());
gtag('config', '<?php echo esc_js($gid); ?>');
</script>
<script async src="https://www.googletagmanager.com/gtag/js?id=<?php echo esc_attr($gid); ?>"></script>
<?php
}, 1);