Google Analytics is a free tool provided by Google that, among other things, tracks the visitors that visit your WordPress blog or site. The reports can let you know how the visitor came to your site (type-in traffic, clicked from a different site, etc), whether it was paid or organic traffic, and what page they landed on on your site. In some cases you can learn the keyword the user searched if they came to your site from a search engine. You can also learn some information about the visitor, specifically their geographic location.
Get the Code From Google Analytics and Add it to the Header or Footer Template File – or Install a Plugin to do it
It’s actually quite simple to add Analytics to WordPress. The hardest part (which really isn’t that hard) is adding the web site to your Google Analytics account. Once you receive the code, it just needs to be placed within the “background” of your web site to be put in use. It is meant to go on all pages of the site so that they can all be tracked. Since WordPress is a templated system this is very easy to do. It only needs to be added to the header or footer template page to appear on all pages of the site.
It’s not always recommended to modify the theme directly though because when there is a new version of a theme (because of a bug, security loophole, and/or feature upgrade), the changes will be overwritten and need to be reapplied.
Another way is to create a custom function, but a much simpler way is to use a plugin. There are several plugins available that let you paste in your Analytics code, I have no personal recommendation for which one to use. Even some SEO plugins include that functionality. But there still might be no need for a plugin. Your theme may already have a spot for that.
Note: Some plugins, like this one by Yoast, offer some “extras” for Google Analytics.
These days, especially with the advent of frameworks and more sophisticated theme option panels, there is an even easier way of adding the AdSense code. Most of the time the Theme Options will allow you to paste in “header code” or “footer code,” or there may even be a box labelled specifically for “tracking code” or “Google Analytics code.”
Steps to Get the Google Analytics Tracking Code for Your WordPress Site
Following are the steps to get the Google Analytics code to be used in one of the spots mentioned above.
1. Create a Google (Gmail) account if you don’t already have one. Log in to that account.
2. Visit www.google.com/analytics.
3. Click the Sign in text link near the top of the page. You should automatically be logged in to Analytics after clicking that link if you are following along from step 1.
4. Click the Admin button from the top right of the screen.
5. Click the +New Account button near the left of the screen.
6. Scroll down and fill in the fields: Web Site Name, Web Site URL, Industry Category (this makes it so Google can offer tailored reports for your industry – it’s currently a “future” feature for the most part), Time Zone, and Account Name (the name of your business perhaps – you can include multiple sites under one account).
7. Choose the level of Data Sharing that you are comfortable with, and click the blue Get Tracking ID button.
8. Read the terms and click the I Accept button (presuming you do).
9. You will be presented with a Tracking/Property ID, which usually starts with “UA” and tracking code. It depends on the method that you are using to add it to your blog, as to which one to pick. Some Google Analytics plugins will just ask for the Tracking or Property ID. But the more general options (that support multiple tracking methods and scripts) will require the full code.
Google now recommends that the code be placed after the opening “body” tag in the HTML code. Keep that in mind when given the choice. Most up to date plugins and themes will be aware of the best placement and it will be included in the appropriate place so don’t worry much about this.