Last active
December 20, 2017 17:34
-
-
Save fernandiez/585d2402b7325d31f77434a4231251e9 to your computer and use it in GitHub Desktop.
Simple Google Analytics WordPress plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* | |
* Simple Google Analytics WordPress plugin | |
* | |
* @link https://www.fernan.com.es/ | |
* @since 1.0.0 | |
* | |
* Plugin Name: Fernan Google Analytics | |
* Plugin URI: https://www.fernan.com.es/ | |
* Description: Plugin para añadir Google Analytics en el sitio web. | |
* Version: 1.0.0 | |
* Author: Fernan Díez | |
* Author URI: https://www.fernan.com.es/ | |
* License: GPL-2.0+ | |
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt | |
* Text Domain: google-analytics-plugin | |
* Domain Path: /languages | |
*/ | |
// Adds Google Analytics code to the header | |
function fernan_analytics_code() { ?> | |
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-1"></script> | |
<script> | |
window.dataLayer = window.dataLayer || []; | |
function gtag(){dataLayer.push(arguments);} | |
gtag('js', new Date()); | |
gtag('config', 'UA-XXXXXXXX-1'); | |
</script> | |
<?php } | |
add_action('wp_head', 'fernan_analytics_code'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Important reminder!
Replace in both places:
"UA-XXXXXXXX-1"
with your tracking code:
"Your Google Analytics own tracking code"