[Video]How to Add Google Analytics Code to WordPress Website (Dashboard & FTP Method)
Jonathon Moore – with Webdigia here. We have another WordPress Tutorial. This one is going to be on how to add your Google Analytics code to your WordPress installation. There are several ways to do this (tip: sometimes themes include an area in the theme options panel too!) and what we’re going to do is walk you through two ways. We’re going to walk you through how to do it in the dashboard and the more advanced way on how to do it using your FTP client and editing the file directly.
So, before we get started we need to have your Google Analytics code – so let’s jump over there and get one. Go ahead and if you don’t have a Google account, create one. If you do have a Google account, go ahead and sign in. As you can see, I’m already signed in. What I like to emphasize here, is to make sure you are signed in under the right Google account. We have a lot of clients who sign in under their personal accounts and then it causes a lot of confusion later; so just make sure you’re under the right Google account.
After we hit sign up here, it’s going to walk us through adding our first website to the Google dashboard. Go ahead and hit sign up (unless you’ve already done this step) and here we can start adding our website. What the website name is, is more-so for your reference in the Google Analytics dashboard. What we’re going to do here is add the name that we can refer to, we’re going to add the website URL, industry (the one specific to your website), and your time zone. Now this is also just for cosmetic issues or organizational issues in this case. In the dashboard you can have multiple sites, so you can organize those under certain categories and for this case since I’m only using one I’m going to use ‘main.’
Now for these additional, make sure you read over them and decide if you like them or not. For this case, I’m going to leave them both checked; it doesn’t bother me at all. Get the tracking code and go ahead and read over the terms and accept it. Now here we have our page added and we can tell because it’s giving us all the data for it and there are no errors. Don’t worry about any of this extra stuff; all you need is what’s in this box. You need from this script tag, to this script tag. Go ahead and right click and copy that or cmd copy or control copy; whatever platform you are on. Now keep track of that. You can log back into your Google Analytics account and retrieve that information again, but I always like to make a text file and to save it in there so I can refer to it if I ever need to.
Let’s go ahead and let’s do the WordPress installation using the WP dashboard. Here we are, this is a fresh install of WordPress. I’m using the very basic theme, but make sure you choose the right theme when you’re editing. Go ahead after you log into your WordPress, go to the appearance and we want the editor. Now over here on the right-hand side this is all the files. We want the footer file and the reason behind that is the footer file is one of the last files to load and that helps us to make sure we actually get someone who loaded the full website and not someone who accidentally clicked in and instantly clicked back.
This won’t run the analytics script until they fully load the website, so using the footer is just a good method to make sure you’re getting the best results. Go ahead and click on the “footer;” you’ll pull up the file; this is the actual file content. Now what were looking for is you should have these two ending codes, or at least this body code right here and what we want to do is we want to put the code right before that. All I did was command+v or control+v to paste that code in there. What we want to do is confirm that we have the ending script, the beginning script, and make sure nothing is messed up in-between; that’s exactly what Google gave us – perfect. Now that’s it, that’s literally all it is to add it to your WordPress installation.
Some things to look for: make sure you didn’t add it to this, inside of this right here. If we added it there, that would actually break the code and cause an error. What we want to do is make sure we’re not inside of any ending codes. We don’t want to be inside of any comments or any of these tags. We simply want a fresh line to paste it onto. We’re done; go ahead and click the “update file” and it will tell you that it was done by giving you this notification here. You are done; let’s go make sure that our WordPress installation actually has it, so what I did was I clicked up here which will take us to our homepage.
Now we want to view the page source, depending on which browser you are on you can right click and show page source or view page source as it might be called, and let’s scroll down all the way to the bottom (this is Safari for reference) and what we’re looking for is this script code that we just pasted in. We can see its right there; perfect! We’re done, that’s all it is.
Now, I’ll go ahead and show you how to do it using the FTP client and we’re going to use the client FileZilla. If you don’t have FileZilla, it’s a free download for both Windows and Macintosh; so go ahead and Google FileZilla and you can download it. Let’s jump right into that. So we have FileZilla here open and as you can see I’m logged in. If you’re using this method I’m going to just assume that you know how to login to an FTP client and you should have this information from your host. Now what we did here is we navigated (here’s our home directory) and we’ve navigated into our wp-content > themes (make sure you choose your right theme).
Now a tip to make sure that you’re choosing the right folder with your theme; go back to your WordPress website here, view that page source again and within the header you should be able to see where the CSS file is being pulled from. In this case, we actually have an image down here being pulled from our website inside the wp-content folder, inside the themes folder and then here is our selected theme. That’s one way that you can confirm what the actual folder for your theme is. So, within the twenty-eleven theme we’re going to go inside and we’re going to look for that footer.php file.
There are several ways you can edit this file in FileZilla and this isn’t a FileZilla tutorial so I’m just going to show you the easiest way that I use. Go ahead and right click on it and then click view/edit and I’ve already opened this so you won’t get this box unless you’ve already opened it; but let’s just discard and open a new one. Okay, this is the same thing that we saw inside the WordPress dashboard, it’s just in our own editor. This particular editor is Sublime; you may have just a plain text editor.
Once again, we’re going to scroll down and look for that body tag and we’re going to paste that script (Google Analytics code) right before it. Okay we’re going to confirm script start, script ends and everything between it. We’re going to save it; in this case command+s (Mac) or control+s (Windows) and we can simply close out of our application. Once we click back into FileZilla it’s going to check if that file had been changed or updated in any way. This box will pop-up for you and we want to say “yes” let’s upload the new one so that it overwrites the old one.
Now let’s jump back into our browser to check, okay has this been added to our website. View the page source and as you can see once again it’s down here. All I did, was I’ll repeat that once more. I refreshed the page to make sure it was there. I showed the page source and I scrolled down to the bottom to confirm that it had loaded. That’s all it is, you’re done now; your Google Analytics is on your WordPress installation. Of course, as always Webdigia does offer website maintenance which would cover such things as adding this analytic code to your website if you don’t have time or if you just don’t want to mess with it. Go ahead and contact us at webdigia.com.