How To Add Google Analytics to Your WordPress Website

There are a couple of ways to add Google Analytics to WordPress using the code snippet. Sometimes the easiest solution is to just add another plugin. While that may do exactly what you want, it can also come with more ads on your dashboard but more importantly, you can’t be sure what it’s really doing.

So, with that in mind, I am going to walk you through the quickest way to add Google Analytics to your theme.

Where to start

We’re going to add our Google Analytics tracking code to your themes functions.php file. We will create a new function that contains the code snippet provided by Google.

NOTE: For precautionary reasons, it’s best to create a backup copy of the file before you modify it.
  1. You can either open your themes functions file through the admin (Appearance -> Theme Editor) or open the file using a text/code editor. If you’re not a developer/familiar with SSH/FTP then the first option may be for you, otherwise just reach out to someone who can help with this part.
  2. Next, just copy the snippet below and paste it into the end end of that file.
    add_action('wp_head','insert_google_analytics', 20);
    function insert_google_analytics() {
      <!-- Paste Your Google Analytics Snippet Here -->
      <!-- See for instructions -->
  3. Now all you need to do is save your changes and that’s it!

Now, not to contradict myself…

I have made this available as a plugin which you can download on the WordPress plugins page. As above, it’s very light and very simple so feel free to download it and see how I have put it together.

Leave a Comment

Your email address will not be published. Required fields are marked *