aoline.com simple non technical information

Tracking web visitors across sessions

With bad press and rogue use this topic has caused heated arguments. However, all web users leave behind a trail of information which cannot be helped as it is necessary for the internet to work. This information is scattered about on web servers as you browse.

This article focusses on using some of this information to help log returning visitors to your website. I use this technique to improve my website so it delivers the content in the way people want to find it.

For example, if I have a useful page. I know it is useful because it is a popular page with a high proportion of visits to it. I know it is popular from the logging information left behind under normal browsing conditions. This page however might be situated a few pages away from my home page and in fact quite tricky to find normally. Logging the paths that people take to get to that page may show me that it takes many clicks. I want to improve things for my visitors so I change the structure to my links to help people find that page more easily. I am sure most reasonable people think that this sort of logging is important and useful.

So to enable this detail we need to modify the way Apache handles logging. I want Apache to set a cookie and a unique id for each url.

Try to enable mod_usertrack with the following command:

a2enmod

Choose usertrack from the available list and then reload Apache:

/etc/init.d/apache2 reload

If all goes well you'll be ready for more config however let's also enable mod_unique_id by running a2enmod again and reload apache.

Now this is set edit your apache2.conf file:

pico /etc/apache2/apache2.conf

Find your LogFormat section and modify your combined as below:

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" \"%{Cookie}n\" %{UNIQUE_ID}e" combined

You can see the addition of Cookie & UNIQUE_ID will now add more information to your logfile.

Keep browsing your apache2.conf file until you find your <Directory> section and modify as follows:

<Directory /home/sitename/htdocs/>
  CookieTracking on
  CookieDomain .sitename.com
  CookieStyle Cookie2
  CookieName customer_ID
  CookieExpires "6 months 2 weeks 2 days 7 hours"
</Directory>

Check also that the <VirtualHost *> for this domain is actually using the CustomLog /var/www/path/to/access_log Combined as you specified above.

Now save and exit apache2.conf and browse your site before checking your logfile. You should now see this extra cookie and unique id information being logged.

Here is a link to a useful and related article: www.kuro5hin.org/story/2006/2/20/213832/821