Celtnet Information:
How to Create your Own Site Access Log
As I found to my cost, not all UNIX hosting environments come with full access logs. Initially this wasn't a problem for me as I was mostly fixed on growing my website and on getting the basic advertising and publicity for my website going. Indeed, between varous mechanisms I managed to increase the traffic to my site over 30x (to learn how I managed this see my How to Maximize your Web Traffic page). But certain areas of the site seemed to be preforming much better than others. I knew which those areas were based on Google AdWords campaigns, but I had no idea whether that was because I wasn't getting enough visitors to those areas of the site or whether the ads on those pages just weren't converting. This is where the absense of proper server logs began to be a major problem. How was I to know what my website was doing when I just didn't have the information about who was visiting those pages. Were they even being crawled by the web indexing bots?
Of course, my ISP had the option of ading logging to my site. But that was an additional £3.99 ($8.00) a month on top of what I was already paying them. As a programmer (and needing all the money I can get for other things) I decided to see if I couldn't circumvent this problem myself. After all, with the various programming languages I know, surely I could come up with a way of doing this for myself.
A little head scratching and some playing with various bits of code later and I had something that could create just what I wanted: a site access log.
Site Access Logs
A site access log is basically a text file that stores a record of who visits your site and when. It can either just tell you who's come to your site or it can tell you precisely which page they've visited. This can be invaluable information to let you know where people are coming into your site and where they are not. Such logs also let you know peoples' behaviour on your site. Are they staying to expore, or are they just coming into a single page and then leaving. With this information you can help increase the 'stickiness' of your site to make it more visitor-friendly. Or you can seek to chage visitors' behaviour to drive them to areas of the site that generate more revenue for you.
If you know things like how a visitor moves through your site or how many seconds it takes for a visitor to navigate from one page to another you can start playing with your site to optimize your pages and the layout of your site so that it can perform better.
In the end log files can be critical for your website's performance. If you don't have one, then you need one. It's a critical component in your armoury of internet marketing tools.
The Script
The script I produced is given in its entirety below. For it to work you need to create a directory in the base level of your website called 'logs'. All files created by the logging script will be saved in the 'logs' directory. You need to create this directory as, for security reasons, the script does not create directories for you. The script itself is as below.
|
To get the script to work you can either place the code in every page that you want access to recorded in your logs. Alternaively (this is what I do), save the script somewhere as 'logging.php' then call the script in whichever pages you want logged via a PHP 'include' call of the tpye:
|
This script prvides me with all the information I need to keep track of visitors to my site. The $msg variable being the text that's written to the log file. This variable can be set-up however you want to. It works with the parser I've written for the file, but it's not in the common logfile that's supported my all major servers. Still, the variable is easy enough to change and if you want to write output to your log file in that format simply change to output to comply with the W3C's definition. Note that the name for the log file use the ISO date format of Year_Month_Date. This both keeps to international standards and prevents the logs generated a year from today from over-writing today's log.
Include this script in all your PHP-based web pages and you can have full logs for your site (and you may even save yourself some money on your webhosting package!).

Help Stefan Campaign




![Validate my RSS feed [Valid RSS]](http://www.celtnet.org.uk/images/valid-rss.png)
