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.
You can see how to do it in the following tutorial: "How to add Google Tag Manager code to WordPress".
My recommendation is to include this snippet in a custom function plugin.
<?php
/*
Plugin Name: Añadir el script de Google Tag Manager a Genesis
Plugin URI: https://carlosmdh.es
Description: Plugin para insertar los Scripts de Google Tag Manager si tu WordPress esta hecho con Genesis Framework
Version: 1.0.0
Author: carlosmdh
License: GPL 2+
License URI:
*/
// Añadir el código de Google Tag Manager en el <head>
/* Debes sustituir el texto AGREGA AQUÍ EL ID DEL CONTENEDOR DE GTM con el identificador
de tu contenedor de GTM que encontrarás en el apartado de «instalar Google Tag Manager»
de la sección «Contenedor» del Administrador de Google Tag Manager */
add_action( 'genesis_header', 'carlosmdh_google_tag_manager_genesis_1' );
function carlosmdh_google_tag_manager_genesis_1() { ?>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','AGREGA AQUÍ EL ID DEL CONTENEDOR DE GTM');</script>
<!-- End Google Tag Manager -->
<?php }
/* Añadir el código noscript de Tag Manager justo antes de la apertura del <body>
*/
add_action( 'genesis_before', 'carlosmdh_google_tag_manager_genesis_2' );
function carlosmdh_google_tag_manager_genesis_2() { ?>
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=AGREGA AQUÍ EL ID DEL CONTENEDOR DE GTM"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
<?php }
?>
I invite you to leave your impressions and/or doubts in the contact form and to suggest new topics that you would like me to cover in these tutorials. I will be happy to answer you by email and write in this blog.