If you use Genesis Framework in your websites, this snippet variant can be used to add the Google Tag Manager container script to your website, taking advantage of the hooks provided by Genesis.
Puedes ver como hacerlo en el siguiente tutorial: «Cómo añadir la etiqueta de Google Analytics a WordPress».
My recommendation is to include this snippet in a custom function plugin.
<?php
/*
Plugin Name: Añadir el script gtag.js a Genesis
Plugin URI: https://carlosmdh.es
Description: Plugin para insertar el script gtag.js si tu WordPress esta hecho con Genesis Framework
Version: 1.0.0
Author: carlosmdh
License: GPL 2+
License URI:
*/
// Añadir el script gtag.js en el <head>
/* Debes sustituir el texto GA4_ID, AW_ID y/o DC-ZZZZZZ con el identificador de
que te suministre la herramienta (Google Analytics 4, Google Ads o Floodlight) */
add_action( 'genesis_header', 'carlosmdh_gtag_genesis' );
function carlosmdh_gtag_genesis() { ?>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=TAG_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments)};
gtag('set', 'allow_ad_personalization_signals', false); /* Esta línea inhabilita el uso
de los datos de Google Signals para crear anuncios personalizados. Si deseas usar esos datos
comenta esa línea */
gtag('js', new Date());
gtag('config', 'GA4_ID'); // Google Analytics 4 ID //
gtag('config', 'AW_ID'); // Google Ads Conversions tracking ID //
gtag('config', 'DC-ZZZZZZ]); // Google floodlight ID //
</script>
<?php }
?>