Get a professional website for $99 per month. One week turnaround.

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 () { ?>

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

  gtag('config', 'UA-XXXXXXXX-X');

<?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