Listen up: If you’re not tracking visitor stats on your website, you’re missing out on insightful data that reveals how your site is performing. In this beginner-friendly tutorial, I’ll show you how to add Google Analytics to your WordPress site with ease. Sounds good? Let’s dive in!
Before we get started, let me give you a quick gist of what Google Analytics is all about and why you should install it in the first place.
Google Analytics is the most popular and free analysis tool that—among many things—keeps track of your site’s traffic activity, goals progress and speed performance.
And fortunately for everyone, it’s quite easy to set up an account and get started.
Things you’ll be able to watch include:
- When and how many visitors are coming to your site
- Where on the web they came from or how they found your site (e.g. Google search, social media links, referral from another site, etc.)
- Which devices they’re viewing your site from (desktop, mobile, tablet, etc.)
- Which geographic location (country) they’re visiting from
- What pages on your site they landed on
- How long your visitors browse your site on average
- And many other things
It doesn’t matter how small your site currently is. The sooner you get started tracking data, the sooner you can begin understanding your users and their needs.
As your website grows, this data helps you determine which direction you should go in terms of design, layout, what kind of content to create (based on popularity), and which content or parts of your site need to be optimized.
You can also gain a better understanding of how your advertisements, promotions, and conversion goals are doing.
Without tracking this kind of data, you’ll be shooting in the dark with every move you make, hoping you’ll somehow make major strides.
You simply won’t know whether you’re making progress or wasting time and money. Not ideal, right? For this reason, my team always makes sure this is taken care of for our customers’ sites.

So, assuming you haven’t done this before, let’s get you set up and I’ll show you how to connect your Google Analytics account to your WordPress site using different methods.
Here’s what I’ll cover with you:
Toggle Table of Contents- How to Setup a Google Analytics Account
- 6 Ways to Add Google Analytics to WordPress
- How to Add Google Analytics Tracking Code to Your Theme’s Header File
- How to Add Google Analytics Tracking Code to Your Child Theme’s Functions File
- How to Add Google Analytics to Your Genesis Framework Theme
- How to Add Google Analytics Tracking Code to Your Code Snippets Plugin
- How to Create Your Own Google Analytics Tracking Code Plugin
- Installing Google Analytics Tracking Code with the Analytify Plugin
- Share / Sign Up / Comment (We Appreciate It!)
How to Setup a Google Analytics Account
To make sure everyone is on the same page, I’m going to assume you don’t have a Google account. (In other words, you’ve never signed up for Gmail, Google Search Console or any of Google’s other services.)
Once you’ve got one, you’re ready to sign up for Google Analytics. So let’s get started!
Step 1: Head over to the Google Analytics homepage (www.google.com/analytics
) and click the SIGN IN link.
Step 2: A menu will appear, click Analytics.
Step 3: Next, you will be prompted to sign into your Google Account. But since you don’t have one, click Create account.
Step 4: Go ahead and fill in the details for your new account.
Once you’ve activated your account by confirming your email address, head back to the Google Analytics homepage, click sign in and then Analytics, just like before.
Step 5: On the Analytics 3-step page, click the Sign up button.
Step 6: On the New Account page, fill out the details:
- Choose Website.
- Fill in an account name. This can be anything you want (e.g. your business name, website name, etc.).
- Fill in your website’s name. For our foxqi.com demo site, as an example, I’d call it FoxQi.com.
- Choose the HTTP(S) protocol and enter your website’s URL address. For our demo site, it would be
http://foxqi.com
. - Choose the category that best fits your website and business, then choose your country and time zone.
After that, choose your preferences in the Data Sharing Settings section:
I normally check the Technical support and Account specialists options.
Once you’re done, click the Get Tracking ID button which will take you to your site property’s analytics tracking code page.
Step 7: Scroll down the tracking code page until you see the Website tracking header with a box below containing your tracking code script.
Until you’ve figured out how you want to implement your tracking code, you have two options here:
- Copy everything inside the box and paste it into an empty
.txt
document (use an editor like Notepad or TextEdit in plain text format) and save it for later; or - Bookmark the tracking code page so you can come back and get your tracking code later
Whichever option you choose, well done, because you’re now ready to add your tracking code to your WordPress site.
Let’s carry on!
6 Ways to Add Google Analytics to WordPress
All right. I will show you a handful of ways to do this, then you can choose the best fit for your needs.
You can add your tracking code to:
- your parent or child theme’s
header.php
file - your parent or child theme’s
functions.php
file - the header and footer scripts box within your Genesis Framework theme’s settings page
- a
functions.php
file in your code snippets or site-specific plugin - a super simple plugin you create just for your tracking code
- any of the free or premium feature-rich Google Analytics plugins that often include user-friendly stats dashboards (I will walk you through Analytify)
Some people want to avoid adding extra or bulky plugins to their sites and would prefer the header.php
or functions.php
approach.
Other people like the simplicity of the dashboards found in feature-rich plugins for convenience and to avoid the overwhelm of Google’s own analytics dashboard.
What do I normally do? I use the Genesis theme settings page or our code snippets plugin if it’s not a Genesis theme.
Whichever option you choose, the only thing I won’t recommend is adding your tracking code to any of your parent theme’s files.
As I mentioned in our tutorial on creating a code snippets plugin, any customizations you make to your parent theme will be lost the next time it’s updated.
You with me? All right. Let’s get started.
How to Add Google Analytics Tracking Code to Your Theme’s Header File
This method requires that you know how to access your site’s files through a control panel (e.g. cPanel) or FTP client (e.g. FileZilla).
The PHP file we’re looking for in your active theme’s folder is called header.php
.
Although you can edit this file directly within your WordPress dashboard, I strongly recommend you don’t do this in case you make a mistake and cause a white screen of death.
So let’s find and edit your theme’s header.php
file using cPanel’s File Manager.
Step 1: Log into your cPanel account.
Step 2: Locate and open the File Manager application within the Files section.
On the left-hand side, you’ll see a list of directories for your cPanel user account. We want to find your website’s root directory, which is typically called public_html.
Click on public_html to load its contents, then locate and double-click the wp-content directory.
Inside wp-content, enter the themes directory.
Within the themes directory, find your active theme’s folder and open it. In the case of our Foxqi.com demo site, the active theme is twentysixteen.
Step 3: Inside your active theme’s folder, find and right-click the header.php
file, then click Code Edit.
If you encounter the code editor prompt, just click the Edit button.
Okay, now hang in there with me. I know that what you’re going to see next might seem daunting. Stay with me.
Step 4: The most challenging part of this method, is finding the right spot to insert your tracking code.
But it’s not that difficult. For the vast majority of WordPress sites, the following is all you need to know: paste your tracking code right above the closing head
tag.
Before I insert my code, this is what the beginning of the header.php
file looks like:
Before you can insert your code, you also need to check that the file contains an action hook called wp_head
before the closing head
tag.
After inserting my tracking code, the file now looks like this:
Once you’ve inserted your tracking code, click Save Changes and feel free to close the editor.
You’re done!
Again, I wouldn’t recommend this method because any time you update your theme, your tracking code will be erased and you’ll need to reinsert it each time. Keep this in mind.
If you have a child theme—or don’t mind creating one—then a better alternative is to add your tracking code to your child theme’s functions.php
file.
Let me show you how to do this next.
How to Add Google Analytics Tracking Code to Your Child Theme’s Functions File
Step 1: Just like you did previously, log into your cPanel account, open the File Manager application, and head inside your themes directory.
Find and open your child theme’s directory.
If you created your own child theme, you’ll know that two files are required to make the child theme work:
- a
functions.php
file - a
style.css
file
If your child theme was created by someone else, then don’t worry about whether or not it has the necessary file for your tracking code. It always will.
Step 2: Right-click the functions.php
file and click Code Edit.
Paste the following code at the bottom of your child theme’s functions.php
file:
Before you save, make sure you replace the bit that says UA-12345678-1
with your own tracking ID.
If you’re not sure where to find your tracking ID, here’s where it’ll be:
And this is how your functions.php
file may look after you’ve pasted the code:
Once you’re done, hit the Save Changes button and feel free to close the code editor.
And you’re done!
How to Add Google Analytics to Your Genesis Framework Theme
I thought I would include a quick section for those of you whose sites are built on the popular Genesis Framework.
You see, the Genesis Framework parent theme comes out of the box with an admin theme settings area where you can easily insert tracking code and other scripts into your site’s header or footer. (Doesn’t matter which Genesis child theme you’re using.)
If you do it this way:
- You won’t need a specific theme file or a plugin for inserting your tracking code
- You won’t need to worry about your tracking code being erased after updating your themes
Let’s dive in.
Step 1: Log into your WordPress admin dashboard.
Step 2: In the admin menu on the left-hand side, you should see a Genesis menu item. You can either click it or hover over it and click Theme Settings from the flyout menu.
Step 3: On the Theme Settings page, scroll down toward the bottom and you’ll see the Header and Footer Scripts box.
- Insert the tracking code you copied from your Google Analytics account earlier.
- If you copied one of my samples, make sure to replace the
UA-12345678-1
bit with your own tracking ID. - Once you’re done, click Save Changes.
That’s all there is to it. Great work!
How to Add Google Analytics Tracking Code to Your Code Snippets Plugin
If you’ve created your own code snippets plugin based on our tutorial, you can add your tracking code to the functions.php
file within the frontend
folder.
Let’s do it!
Step 1: Log into your cPanel account, open the File Manager application, and head inside your website’s wp-content directory.
Open the plugins folder.
Inside the plugins folder, find and open the wp-code-snippets folder.
Next, open the frontend folder.
We’re there! Right-click the functions.php
file and click Code Edit.
Paste the following code inside your frontend folder’s functions.php
file:
If you haven’t already added code snippets to this file, it should now look like this:
Again, remember to make sure you replace the bit that says UA-12345678-1
with your own tracking ID.
Voila! Hit the Save Changes button and feel free to close the code editor.
How to Create Your Own Google Analytics Tracking Code Plugin

Okay, friend, there’s a chance you:
- didn’t follow our code snippets plugin tutorial; or
- you just want to have a separate plugin for your analytics tracking code
In either case, I’ll show you how to create a very simple plugin just for your tracking code.
Roll up your sleeves and let’s get to work!
Step 1: On your computer dashboard, create a new folder called analytics-tracking-code
.
Step 2: Open a blank document using an editor like Notepad (Windows) or TextEdit (Mac). (For TextEdit, make sure to use plain text format.)
NOTE: If you’re comfortable with a code editor, then use that of course.
Paste the following code into your editor:
Your document should now look like this:
Make sure to change the author name, website addresses, and insert your own tracking ID, then save the document inside the Analytics Tracking Code folder and name it analytics-tracking-code.php
.
The .php
extension should automatically convert the document into a PHP file.
Step 3: Right-click the plugin folder and compress it into a zip file.
You should now have a regular folder (left) and a zip file version (right):
Step 4: Log into your WordPress dashboard, go to the Plugins page and click Add New.
Step 5: Next up:
- Click Upload Plugin
- Click Choose File, browse to and upload the
analytics-tracking-code
zip file from your computer - Click Install Now
And finally, activate the plugin once it has been installed.
That’s it! Your plugin will carry out the magic immediately.
Installing Google Analytics Tracking Code with the Analytify Plugin
O.K., so let’s say you don’t JUST want your website’s stats to be tracked, but you also want to be able to get a quick glance at how things are going without having to log into your Google Analytics account.
Analytify is one plugin that’ll let you do precisely that by adding a slick and user-friendly Google Analytics dashboard to your WordPress admin area.
Analytify is my favorite “full-fledged” analytics plugin for projects where a client has requested this feature.
I even went ahead and organized a lifetime license deal with the Analytify team to offer our clients access to the pro version of the plugin for their sites.
Now, as with most analytics plugins, you can also use Analytify to add your tracking code to your site which is what I’ll show you next.
Step 1: Log into your WordPress dashboard, go to the Plugins page and click Add New.
Step 2: Search for “Google Analytics Dashboard By Analytify” and the plugin by WPBrigade should appear as the first result on the left-hand side. Click Install Now and the plugin will be ready to activate shortly.
Step 3: After activating the plugin, Analytify will get its own admin menu item. Hover over it and click Settings from the flyout menu.
Step 4: On the WP Analytify Plugin Settings page, click Log in with your Google Analytics Account.
Step 5: Sign into the Google account you created at the beginning of this tutorial.
Step 5: Give Analytify access to your Google Analytics data by clicking Allow.
Step 5: Time to set up your Analytify profile settings.
- Check the option to Install Google Analytics tracking code and Analytify will automatically fetch and insert your tracking code into your site’s header
- Select your website’s profile from the Profile for posts dropdown
- Select your website’s profile from the Profile for Dashboard dropdown
- When ready, click Save Changes
You can now go to the Analytify dashboard page and check out your site’s stats.
Feel free to return to the settings page and tweak some of Analytify’s options.
Other than that, excellent work!

That was a freakin’ piece of cake, right? Now you can start gathering helpful information for your site. Good work!
If you’ve got any questions or tips you’d like to share, please let us know in the comments below!
Oh, and if this tutorial was helpful to you at all, it’d be super cool if you would give it a share. Highly appreciated!
Thankyou so much for this very comprehensive article on how to add Google analytics to wordpress sites. I really appreciated the screenshots and pointers to where to paste the code. I’d looked at 4 other articles before yours but forgot the steps to finding that pesky header.php file but you led me to it very quickly. Some of us website owners need step-by-step instructions with pics and pointy arrows….just like yours. :)
Hey Annie!
I’m super pleased to hear our guide was useful to you. We try to make them as detailed and easy-to-follow as possible. :-)
If you ended up settling for the header.php method, just remember you’ll need to do it again if you update your theme (unless you did it inside a child theme).
Best wishes.