Skip to content

Instantly share code, notes, and snippets.

@deeman
Last active September 9, 2019 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deeman/f8d621559c9d7067229f20f5a3b8b221 to your computer and use it in GitHub Desktop.
Save deeman/f8d621559c9d7067229f20f5a3b8b221 to your computer and use it in GitHub Desktop.
Google Analytics tracking via Child Theme
<!-- Example with code -->
<!-- Hook-->
add_action( 'wp_head', 'ga_google_analytics', 10 );
function da_google_analytics() { ?>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-xxxxxxxxx-x">
</script>
<script>
// Paste your Google Analytics tracking script here
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-xxxxxxxxx-x');
// Tracking Script - End
</script>
<?php
}
add_action('wp_head', 'wpb_add_googleanalytics');
function ga_add_googleanalytics() { ?>
// Paste your Google Analytics code here
<!-- Global site tag (gtag.js) - Google Analytics -->
<?php } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment