Skip to content

Instantly share code, notes, and snippets.

@BurlesonBrad
Created January 27, 2020 18:27
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BurlesonBrad/a367773496e4f645529a5e979eac1bca to your computer and use it in GitHub Desktop.
Save BurlesonBrad/a367773496e4f645529a5e979eac1bca to your computer and use it in GitHub Desktop.
๐ŸšซNo WordPress plugin needed to add tracking code to the header ๐Ÿ‘
function header_tag_analytics() { ?>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-XX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXX-XX');
</script>
// Add your Tweeder scripts Adroll scripts Facebook scripts BounceX scripts Optimizely scripts or whatever needs to be in the head
<?php }
add_action( 'wp_head', 'header_tag_analytics', 10 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment