Created
May 4, 2018 11:03
-
-
Save UeldoTheme/e4afb873417b68978b79593812f516d2 to your computer and use it in GitHub Desktop.
Simple plugin to add Google Analytics tracking code to your WordPress
This file contains hidden or 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: My Google Analytics Tracking Code | |
Description: Add Google Analytics tracking code to WordPress website | |
Version: 1.0 | |
*/ | |
add_action( 'wp_head', 'my_google_analytics_output', 1 ); | |
function my_google_analytics_output() { | |
?> | |
<!-- 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> | |
<?php | |
} | |
/** | |
* | |
* end of plugin. | |
* | |
*/ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment