• 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

Cómo añadir el script gtag.js a WordPress

23 enero, 2023

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».

Mi recomendación es que incluyas este snippet en un plugin de funciones personalizadas.

<?php
/*
Plugin Name: Insertar gtag.js en WordPress
Plugin URI: https://carlosmdh.es
Description: Plugin para insertar gtag,js
Version: 1.1.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( 'wp_head', 'carlosmdh_gtag' );
function carlosmdh_gtag() { ?>
	<!-- 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 }
?>

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.

WordPress

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