Created
May 22, 2018 13:44
-
-
Save dianewallace/2eb956254d05275180a221bd650feee9 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Plugin Name: Simple Google Analytics Plugin | |
* Plugin URI: http://dianewallace.com | |
* Description: Adds a Google analytics tracking code to the <head> of your theme, by hooking to wp_head. | |
* Author: Diane wallace | |
* Version: 1.0 | |
*/ | |
add_action( 'wp_head', 'sga_google_analytics', 10 ); | |
function sga_google_analytics() { ?> | |
<!-- Global site tag (gtag.js) - Google Analytics --> | |
<script async src="https://www.googletagmanager.com/gtag/js?id=XX-XXXXXXXXX-X"></script> | |
<script> | |
window.dataLayer = window.dataLayer || []; | |
function gtag(){dataLayer.push(arguments);} | |
gtag('js', new Date()); | |
gtag('config', 'XX-XXXXXXXXX-X'); | |
</script> | |
<?php } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment