How to Add Google Analytics to WordPress

Home WordPress How to Add Google Analytics to WordPress

February 21, 2022

In this WordPress tutorial I will show you how I like to add Google Analytics code to all our websites.

Code Snippets Link:


  • 0:00 Introduction
  • 1:00 Add code to Code Snippets
  • 3:15 Frontend testing

Code Snippet:

					add_action( 'wp_head', function () { ?>

 <script async src=""></script> <script>window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-XXXXXXXX-X');</script> <?php }, 1 );

*Some of the links on this page are affiliate links, meaning we may receive a commission if you follow them. This allows us to continue providing free content and educational resources for you. Thank you for supporting our small business!

More Free Resources

Join Our Community

Sign up to receive free resources in your inbox every week.

Wicky Design YouTube

Join Our Community

Never miss a post! Join now to receive helpful resources, tips, and tutorials in your inbox weekly. Registration is FREE and emails are delivered every Monday morning.