How to Add Google Analytics to WordPress

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

Code Snippets Link:
https://wordpress.org/plugins/code-snippets/

Timestamps:

  • 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="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-X"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-XXXXXXXX-X');
</script>

<?php }, 1 );
				
			

Free Brand Messaging Worksheet

Define Your Voice and Connect with Your Audience

More Free Resources

Let's Work Together

Big ideas start with a quick chat. Let’s talk!