• Skip to main navigation
  • Skip to main content
  • Jump to the main sidebar

Carlosmdh

  • Migra ahora a Google Analytics 4
  • Blog
  • Snippets
  • Tutorials
  • Q&A GA4
  • About Me
  • Contact Me

Adding Google Tag Manager code to Genesis

5 junio, 2021

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.

No category

Sidebar

Sidebar-Alt

Blog - Snippets - Tutorials

Privacy Policy - Cookie Policy - Change your Consent


carlosmdh © 2023 · Made with by carlosmdh

We use cookies to give you the best experience on our website.

Puedes aprender más sobre qué cookies utilizamos o desactivarlas en los ajustes.

Carlosmdh
Powered by  GDPR Cookie Compliance
Privacy summary

This website uses cookies so that we can provide you with the best possible user experience. Cookie information is stored in your browser and performs functions such as recognising you when you return to our site or helping our team understand which parts of the site you find most interesting and useful.

Strictly necessary cookies

Strictly necessary cookies must always be enabled so that we can save your cookie settings preferences.

If you disable this cookie we will not be able to save your preferences. This means that each time you visit this website you will have to enable or disable cookies again.

Cookies de terceros

Esta web utiliza Google Analytics para recopilar información anónima tal como el número de visitantes del sitio, o las páginas más populares.

Dejar esta cookie activa nos permite mejorar nuestra web.

¡Por favor, activa primero las cookies estrictamente necesarias para que podamos guardar tus preferencias!

Cookies adicionales

Esta web utiliza las siguientes cookies adicionales:

(Lista aquí las cookies que estás utilizando en la web.)

¡Por favor, activa primero las cookies estrictamente necesarias para que podamos guardar tus preferencias!

  • Español
  • Français