Google Analytics is a web analytics service offered by Google that allows you to track your WordPress blog visitors and their behavior. With Google Analytics Dashboard you will be able to do many things such as:
- See how many people are currently online (Yes! In Real Time) on your site?
- See the geographic location of your website visitors.
- Check the traffic sources of all your visitors. These traffic sources can be search engines, Twitter, Facebook and other websites on the internet.
- Check what device (mobile, tablet, desktop, laptop etc.) your visitors are using?
- See your site’s top content.
- Track your earnings like your AdSense revenue.
- Check incoming search keywords.
- Check the page load time of individual web pages.
- Check Bounce Rate.
- and do much more.
Google Analytics is one of the best free Analytics program on the web that everyone’s using. In this step-by-step guide, you will learn how to integrate Google Analytics in your self-hosted WordPress blog.
1. Go to http://www.google.com/analytics/ and click on Sign In OR Create an account links present at the top right corner of your screen.
If you click on Sign In then you are required to log in to Analytics using your existing Google/Gmail account. And if you click on Create an account hyperlink, then you need to create a brand new Google/Gmail account so that you can access Analytics using it.
2. Once you are successfully logged in/have created a new account, the next page will ask you to Sign up for Google Analytics:
Click on Sign up button present just below Start using Google Analytics and you will proceed to the next step.
3. The immediate next page will ask you what would you like to track using Google Analytics? Website or Mobile Application?:
Click on Website tab and start entering/selecting following details:
- Account name: In this field you can enter your company name or your own name.
- Website name: Enter your blog’s name in this field, for example: BeginWP.
- Website URL: Enter your website URL accurately in the field provided just after http://. Keep in mind that there is no need to enter www if your blog URL don’t have www in it. Also if your blog is using https:// protocol for delivering content to your website visitors and search engines, then you need to select https:// instead of http:// from the drop down menu.
- Depending on the niche of your blog, select your industry type from the drop down menu which can be Computers and Electronics, News, Finance, Sports etc.
- Select your country and Time Zone under Reporting Time Zone.
Now click on Get Tracking ID Blue button and you will be asked to accept certain Terms and Conditions of Google Analytics program depending on your country/region of residence.
A typical Google Analytics code looks something like following:
ga(‘create’, ‘UA-XXXXXXXX-X’, ‘auto’);
We are now ready to add this code to your self-hosted WordPress blog.
How to add Google Analytics Tracking Code to WordPress?
Once you have obtained your tracking code, it’s time to insert it in your blog. Following are the best ways using which you can insert the code in your blog:
- Manually enter the code.
- Use Google Analytics by Yoast Plugin.
- You are only required to follow any one of the above/following mentioned methods.
Manually Enter Google Analytics Code
Using WordPress’s Appearance Editor you can easily insert Google Analytics code to all your posts as well as pages (including Homepage, Categories and other archive pages). For this you need to follow these steps:
1. Login to your WordPress Dashboard, go to Appearance in the left sidebar and then click on Editor:
2. When the theme editor (theme-editor.php) page opens in your browser, click on footer.php hyperlink displayed on the right under Templates:
3. On footer.php page you need to copy and paste the Google Analytics tracking code just above the closing </body> tag:
4. Once you have inserted the code properly and click on Update File button. WordPress will now save your changes in the database and the change should reflect on all your blog’s pages.
If your theme has an options panel, then you can insert Google Analytics code using it also. For this all you need to do is to follow these steps:
1. Login to your WordPress Dashboard and look for your theme’s name in the left sidebar. Hover on it and click on Settings:
2. You will now be able to see the options panel of your theme. Here look for the option using which you can add a code in the footer of your site, just before the closing body tag (as seen in below screenshot):
3. Once you have inserted the code, click on Save changes button and the change should reflect on all your blog’s pages.
- If you are using some sort of cache plugin like WP Super Cache, W3 Total Cache etc. in your blog, then you need to manually clear the cache completely after inserting the code.
- If you change your theme in near future, then the Analytics code that you have inserted in the footer of your site will be lost. You will have to again insert the code manually in your new theme.
- If you are unable to find closing body HTML tag i.e. </body> in footer.php, then you need to contact your theme developer and ask him the name of PHP file in which the tag is located.
Enter the code using Google Analytics by Yoast Plugin
If you don’t want to add the code manually to your theme or framework, then here’s another easy way to do this. Google Analytics by Yoast Plugin also allows you to add Analytics tracking code in your blog. The main advantage of using this plugin is that it adds some more tracking features to your blog. Follow these steps in order to configure the plugin for your website:
1. Install the plugin to your self-hosted installation of WordPress. Once the plugin has been successfully installed, activate it and go to its settings page.
2. On the settings page, click on Authenticate with your Google account button:
A new window will open which will ask you to login to your Google Analytics account. Enter your Google/Gmail account’s username and password, and if your login is successful you will see following message:
Click on the Accept button and you will be able to see a unique alpha-numeric authorization code for your site in your web browser:
3. You are now required to copy and paste this code on the plugin’s settings page in the Paste your Google Code here field:
Once you have successfully pasted the code, click on Save Authentication code button and the plugin will be fully authorized to access your Analytics account data.
4. You are now required to select a profile (your website name that you entered for generating the code) using the drop down menu of Analytics Profile:
Once selected, click on Save Changes button and it’s all done.
Additional things/features that you can configure in this plugin:
Under General Settings Tab you can set/select following things as per your site requirements:
- Track outbound click and downloads: Check the box in front of this option if you’d like to track clicks and file downloads in your site as Events. You can find this report under Content >> Event Tracking in your Google Analytics account.
- Allow tracking of anonymous data: Check the box in front of this option if you’d like to allow the plugin to track anonymous data and then send the data to its developer. Keep in mind that the plugin won’t send any personal data of your site to the developer. It only sends details about your WordPress settings, themes and plugins.
- Anonymize IPs: If you’d like to add _anonymizeIp to your site so that Google Analytics can anonymize the information sent by the tracker objects by removing the last octet of the IP address prior to its storage, then check the box in front of this option.
- Ignore Users: Enter a list (role) of all the registered users of your site whom you don’t want to track using Google Analytics. By default the plugin won’t track all the Administrators and Editors of your site. You can always remove a user from the list by clicking on the small cross (x) icon present in front of its name.
- Disable Analytics dashboard: If you don’t want the plugin to fetch your visitor’s data from your Google Analytics account and display it in its Dashboard tab, then check the box in front of this option.
Under Universal Tab you can set/select following things as per your site requirements:
- Enable Universal Tracking: If you’d like to enable Universal Tracking for your site then check the box in front of this option. Keep in mind that this feature will only work if Universal Analytics is enabled in your Google Analytics account.
- Enable Demographics and Interest Reports: Check the box in front of this option in order to enable Demographics and Interest based reports in Google Analytics. Keep in mind that this feature will only work if Demographics is enabled in your Analytics account.
- Enhanced Link Attribution: Check the box in front of this option if you’d like to implement an enhanced link tracking functionality for your site.
Under Advanced Tab you can set/select following things as per your site requirements:
- Track download as: Select from the drop-down menu how you’d like to track your downloads? You can track your downloads either as an event or as page views. Keep in mind that if you select page views then your reports may get messed.
- Extensions of files to track as downloads: In this field you are required to enter a list of all those file extensions that you’d like to track when they gets downloaded by your visitors. By default these file extensions are already included in this field: doc, exe, js, pdf, ppt, tgz, zip and xls.
- Track full URL of outbound clicks or just the domain: Select from the drop-down menu whether you’d like to track the full URL of all outgoing links or just the domain name.
- Sub-domain tracking: This option allows you to set the domain that’s set by _setDomainName for tracking sub-domains. By default this field is empty.
- Set path for internal links to track as outbound links: If you want to track all your site’s internal links that begin with /affiliate/, enter /affiliate/ in the field provided. In case you want to enter multiple prefixes, then you can separate all of them with commas like /affiliate/, /recommended/, /go/ etc.
- Custom Code: If you are a developer or an advanced user and would like to add a line of code just before the _trackPageview call, then you can enter the code in the field provided.
So that’s it. Hope this step-by-step guide will help you in adding Google Analytics to your WordPress site.
Tip: There’s also an alternative to Google Analytics which is known as Statcounter. Here’s how you can add Statcounter to your WordPress site.