Before we get into this I should point out that this How-to Tutorial is pointed towards adding the Google Analytics code to your Header, manually and without using a plugin.
There are quite a few reasons why I prefer this method but let me highlight something really quick. If you are installing a plugin for the sole reason of adding your analytics code to your website, that’s just wrong on so many levels. Plugins are designed to simplify the process of developing or designing a website but adding a bit of copy and paste code to your header.php file is really not complicated.
Relax though, you aren’t to blame – WordPress is opensource and some of those plugin developers can be pesky scam artists because it will take you a lot quicker adding the code manually than search in WordPress Repository for a suitable plugin and installing and setting it up – And trust me, this instruction article isn’t by any means the only one out there.
It’s technically safer but by no means difficult and requires but a few steps. Follow this exactly and you won’t run into any issues – In case you do though, we’re not responsible for any problems that may arise from this, so please be sure you have a back up of your site, just in case 😉
So, off we go!
In your WordPress Dashboard – Hover over “Appearance” in the sidebar, then in the sub-menu, click “Theme Editor”
Next, head over to the right and click on the “header.php” file – Importantly, on some themes or on older versions of WordPress, you may get a file title but not the actual file name, in that case, the title will be at the top and the file name will be at the bottom – Make sure you click on “header.php” ONLY IN ALL CASES.
Head on to Google Analytics Tracking code – If you don’t know where to find it, it’s simple. When in your Analytics Dashboard, simply look at the bottom left of your screen and select “Admin”, then within the middle (property) column, click on the fourth option from the top called “Traffic Info” then select “Tracking Code” and you’ll find the screen shown below.
This is how simple it really is, even Google tells you what to do which I’ve circled for you to see – So basically copy and paste the code as the first item into the <head>.
So, then, we go ahead and copy the code below and move over to the following screenshot.
So back at WordPress, you’ll find the <head> tag and paste the code from Analytics directly UNDER (Following the line after) – Importantly for those not very familiar with php, you’ll find two HEAD Tags, one that looks like this <head> and a closing tag that looks like this </head> – This code ALWAYS gets copied in the opening tag <head>.
I know I may have confused you or made you read twice or thrise but if you don’t know php or if you’re not familiar with it, it can be confusing and we have endless problems with customers confusing the two or assuming they are the same thing – Even our newbie Website Designers have no idea what that stuff means until we teach them some php kung-fu.
This step is kinda easy, or at least the easiest on this How-To… See, I made you read more than absolutely necessary 😉 Just click update and you’re done 🙂
This step is about making sure you’re coding skills paid off – So head back to Analytics, open up your website in a new tab or window and wait a few seconds and you’ll see the “0” turn to “1, etc.” meaning that Analytics is working!
Congratulations! If this was a first of many for you as a Designer or a small Business Owner starting up his first website, you just did a bit of coding and you can now see who’s visiting your site, where they’re going and what they’re doing.
I hope you’ve found this How-To Instruction super easy and wish you all the best in your website design or development journey – Remember, we’re always here for support just visit our Contact page and fill in the form.
Till next time…