Add Google analytics to head in Functions file

add_action( 'wp_head', 'atk_add_google_analytics', 999 );
function atk_add_google_analytics() {
     echo "
     <!-- Global site tag (gtag.js) - Google Analytics -->
<script async src='https://www.googletagmanager.com/gtag/js?id=UA-YOUR UA NUMBER HERE'></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'YOUR UA NUMBER HERE');
</script>
";
}

No Comments

Sorry, the comment form is closed at this time.