How to Add Google Analytics to WordPress

Google Analytics Code for WordPress Tracking Tutorial

Google Analytics is a free tool to measure a lot of information for your website. You can measure visits, goals, demographics, what are your most popular pages, and much more. There are plugins for WordPress that can help you with adding this, but I am going to focus on using the code on your website. If you do want a great plugin to help though, you should check this plugin from Yoast. As a note, there are some things that you can do without relying on plugins for WordPress. Less reliance on multiple plugins will allow your website to run more efficient. If you are curious about that, you can head over here and learn how to compress files for your WordPress website.


Google Analytics to Copy the Code


Assuming you have Google Analytics set up, you will need to head over to the Admin –> Property–> Tracking Info –> Tracking Code. You will see a code that looks like this below. You simply need to copy all of this code and head over to your WordPress site to put the code on just once. If by any chance you don’t have Google Analytics set up, you can check out this helpful site from Google.


Google Analytics Code for WordPress Tracking Tutorial


Adding Google Analytics Tracking Code to WordPress


With the code copied from Analytics, we are going to head to our editor section of our dashboard. You will find this under Appearance –> Editor. From there, we are going to look for either the header or the footer section to place the code. I personally put my code at the end of the of my site to allow Google and Bing to load my site a bit faster (less code at the top of the page, makes sense), so we are going to work with that section for this tutorial and use the header.


Within the head section of my site, I am going to run a control find (CTRL +F) to find the code </head> on my site. This line of code with the slash signifies the end of the section of my site. I am going to paste my Google Analytics code directly above this line. See below for where I placed my code. As a note, I do have two other lines of code right above the </head>  section in this example below. You won’t have that for this example. Those two lines of code are my lines of code verifying Google Webmaster Tools and Bing Webmaster Tools. The steps to add that are exactly the same as Google Analytics.


Adding the Code Easily to WordPress from Google Analytics


The moment I have my code on, I am going to click on update and run a test. I am going visit my website and go back to Google Analytics. Within Google Analytics, you will head over to the real-time data section to see current active users on your site. If the code is on your site, you will see some activity within the real-time data section. If that is the case, you are good. What is good about doing it this way is that this Google Analytics code will actually cover all of your pages on your website.


What to Do if Google Analytics Does Not Track Visits?


Don’t sweat. There are a few reasons why this is the case. Google even tells you to let about 24 hours to pass by for tracking to take place. If the 24 hours do go by, you might have to go through some more steps.


First, I would check to make sure you are not blocking your IP address from Google Analytics. For my blog, I block the IP address of my apartment so I don’t count myself as a visitor when I am making changes to your site. To check this, you will need to head over to Admin –> Accounts –> All Filters. Look to see if your or someone on your team is blocking your visits from Google Analytics.


Second, I would open up your website with a browser like Google Chrome and right click on view source. From there, you just need to type in “UA-“. This will either come back with something or nothing. If it comes back with a find, you can scroll to see where the code is on your site. If your code is there, you should run a spot check to make sure you copied the entire code from Google Analytics into your WordPress Site. Even one part of the code missing will throw this off. If you run the control find and you can find your code, you might not of saved the code in the editor section of WordPress. If that is the case, you will need to copy and paste the code again on your site.