Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple Google Analytics WordPress plugin
* Simple Google Analytics WordPress plugin
* @link
* @since 1.0.0
* Plugin Name: Fernan Google Analytics
* Plugin URI:
* Description: Plugin para añadir Google Analytics en el sitio web.
* Version: 1.0.0
* Author: Fernan Díez
* Author URI:
* License: GPL-2.0+
* License URI:
* Text Domain: google-analytics-plugin
* Domain Path: /languages
// Adds Google Analytics code to the header
function fernan_analytics_code() { ?>
<script async src=""></script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXX-1');
<?php }
add_action('wp_head', 'fernan_analytics_code');
Copy link

fernandiez commented Dec 20, 2017

Important reminder!

Replace in both places:
with your tracking code:
"Your Google Analytics own tracking code"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment