Skip to content

Instantly share code, notes, and snippets.

@alcaudon89
Last active March 22, 2020 12:06
Show Gist options
  • Save alcaudon89/4b06a708b094fa4c76903c8f4ce40635 to your computer and use it in GitHub Desktop.
Save alcaudon89/4b06a708b094fa4c76903c8f4ce40635 to your computer and use it in GitHub Desktop.
Añadir el código de seguimiento de Google Analytics para Wordpress sin plugin.
<?php
/**
* Plugin Name: Google Analytics
* Plugin URI: https://www.davidrd.es/trucos-wordpress/analytics-sin-plugin-wordpress
* Description: Añadir el código de seguimiento de Google Analytics para Wordpress sin plugin.
* Version: 1.0
* Author: alcaudon89
* Author URI: https://davidrd.es/
* License: GPLv3 or later
*
* Agradecimientos: https://www.wpbeginner.com/beginners-guide/how-to-install-google-analytics-in-wordpress/
*
**/
add_action('wp_head','my_analytics', 20);
function my_analytics() {
?>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-X"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXX-X');
</script>
<!-- don't erase below -->
<?php
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment