Skip to content

Instantly share code, notes, and snippets.

@stacklast
Created July 10, 2021 00:02
Show Gist options
  • Select an option

  • Save stacklast/8c15515f2893115d841b38d20b814e67 to your computer and use it in GitHub Desktop.

Select an option

Save stacklast/8c15515f2893115d841b38d20b814e67 to your computer and use it in GitHub Desktop.
[WordPress] - Add Google Analytics | Global site tag (gtag.js) - Google Analytics
<?php
// Add Google Analytics
add_action( 'wp_head', 'my_own_analytics', 20 );
function my_own_analytics() { ?>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-X"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXXX-X');
</script>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment