Skip to content

Instantly share code, notes, and snippets.

@UeldoTheme
Created May 4, 2018 11:03
Show Gist options
  • Save UeldoTheme/e4afb873417b68978b79593812f516d2 to your computer and use it in GitHub Desktop.
Save UeldoTheme/e4afb873417b68978b79593812f516d2 to your computer and use it in GitHub Desktop.
Simple plugin to add Google Analytics tracking code to your WordPress
<?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