You know the situation: You make your wordpress site a little bit better every day. But: How many visitors do you have? Where do they come from? What pages are they reading? And how do they react to various articles and changes on your site?
Right, you need statistics.
One of the most convenient ways to get some statistics is to use google analytics. As with most other things, there are good and bad sides.
The good things:
- As I just mentioned, it’s convenient. You could be collecting your first statistics in 20 minutes from now (especially with some help from me in this article).
- Right out of the box, Google analytics gives you lots of very useful information. (It’s possible to get even more details, but then you may need to add specific scripts for various events etc.)
- It doesn’t cost you any money. At least not in the basic configuration.
The bad things:
- By cooperating with google, you give this multi-billion global business detailed access to information about visitors’ behavior inside your site, allowing them to fine-tune profiles and ads even more.
The choice may not be obvious, but I can say that many-many sites do use google analytics.
First, set up an account at google analytics and add a profile for your site (unless you’ve already done that before).
Google analytics will show you a script, that you should include on every page your server sends to its visitors. The script from google will report every page visited once. For a typical blog, you may want to keep better track on how long people stayed on the page. You can read more about this modification in a previous article.
In this article I show how you can create your own, specially crafted plugin, to add the google analytics script to public pages of your site, but only for visitors who are NOT logged in. This way, your own visits to the public side won’t disturb the data! (If you allow your visitors to register with your site, then this solution may not be the best one for you!)
You’re going to create a WordPress plugin that consists of only one single php file. You’ll need to edit the file slightly, to put in the account and site information from google analytics, but that’s easy. The php file you create will look (almost) like this:
In order to edit and use this, you’re better off downloading the file I’ve prepared for you: google-analytics-scripts-mysite.zip
- Download the file (right-click and save as…), edit the enclosed php-file in a text editor (Notepad would work, Notepad++ is better)
- Compress the php-file back into the zip-file.
- In WordPress admin panel, go to Add new plugin and hit the File upload button at the top.
- Upload the file you just zipped.
- Activate the plugin
- Visit your public site with a not logged-in browser and verify in the html-code that the script was output to the browser somehwhere between the <head> tags.
- In google analytics, check that the data is coming in. Quickest is in the section Real time. Notice that the may be some delay from account creation and first visit, until the data starts gathering.
PS! I used PC language in this article (Notepad, right-click etc.) but, of course the same things can be done through other types of computers, too.