Skip to content

Instantly share code, notes, and snippets.

@robertpassaro
Last active April 10, 2016 03:28
Show Gist options
  • Save robertpassaro/760fbc60b366cdcee741e70bef31b30e to your computer and use it in GitHub Desktop.
Save robertpassaro/760fbc60b366cdcee741e70bef31b30e to your computer and use it in GitHub Desktop.
/*--------------------------------------------------------------
# Google Analytics script (gets called into head element)
--------------------------------------------------------------*/
function fq_google_analytics() {
$google_ua_code = 'xxxxxxxxxxxxx'; // Add "UA" code for this site from Google
echo "<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', '" . $google_ua_code . "', 'auto');
ga('send', 'pageview');
</script>";
}
add_action( 'wp_head', 'fq_google_analytics', 10 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment