Skip to content

Instantly share code, notes, and snippets.

@dianewallace
Created May 22, 2018 13:44
Show Gist options
  • Save dianewallace/2eb956254d05275180a221bd650feee9 to your computer and use it in GitHub Desktop.
Save dianewallace/2eb956254d05275180a221bd650feee9 to your computer and use it in GitHub Desktop.
<?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