PHP Traffic Tracker...?
Author
Discussion

mynameismud

Original Poster:

50 posts

247 months

Sunday 4th June 2006
quotequote all
Hi, trying to code my own php based conversion tracker - any pointers on where to start? I'm looking to record the page people leave my site from, along with time and date.

docevi1

10,430 posts

278 months

Sunday 4th June 2006
quotequote all
Whilst as I fancy writing my own as well (it'd be easy in reality), www.statcounter.com has one already which is fairly proficent.

mynameismud

Original Poster:

50 posts

247 months

Sunday 4th June 2006
quotequote all
docevi1 said:
Whilst as I fancy writing my own as well (it'd be easy in reality), www.statcounter.com has one already which is fairly proficent.


Thanks for the quick response , but sadly I have an enormous amount of web traffic and wouldn't qualify for the free version. Plus, I need detailed info regarding every unique visitor visiting, or more importantly, leaving the site.

wildeep

362 posts

279 months

Sunday 4th June 2006
quotequote all
Have you seen AWStats?

Does pretty much everything you would need in a stats package including exit pages and is free to boot.

s a m

509 posts

267 months

Monday 5th June 2006
quotequote all
Depends exactly what you want to track, and how you want to present the data you generate.

To show where they enter and where they leave isn’t too bad and most stats programs, like the suggested AWstats will show all this.

Also, try Google Analytics – there may still be a waiting list though.

You can also look at SawMill, it analyses most log files. www.sawmill.net/




If you want to make your own, here’s one simple method (psudo code):


include(stats.php) – stick this on every page of the site

make a script called stats.php, that does the following:

if (visitor id cookie does not exist) {
create new visitor id (last id +1)
}

save visitor id in cookie with expiry of say 15 minutes
// refreshes the cookie or creates it if its not there already

now insert into your site database’s stats table the visitor id, datetime stamp, page name ($_SERVER['PHP_SELF']; ), and any tracking variables your using (such as “$ad” )

You can use tracking variables on your links from adverts such as yourdomain.com/product_info.php?ad=googleadsense9 – don’t use them for all links as I believe they reduce the links weight when it comes to SEO, but that’s another story. If you’re paying for clicks or banner placement, use a tracking URL with a variable to indicate which advert it came from.

This gives you a simple log of every page visited with most page impressions linked to a visitor, thus crude way of tracking user browsing on your site. You could alternatively create a session if one doesn’t already exist, then use that session id to link the page impression to a user session.

With your raw data you can quite easily establish which page they entered the site on, which page they left the site on (the last page viewed for that visitor/session id) and how many pages they looked at, how long they spent between pages, and produce a history showing their browsing.

Most bots don’t accept cookies, so you could either test cookie acceptance then only log page impressions for visitors that do, or you could assume every visitor id with only one page impression is either a bot or doesn’t need to be considered. You could go a step further by looking at the browser type and logging that, and/or filtering so you only track known web browsers, ignoring spiders and other bots.

You can expand it further by creating a second longer lasting session/visitor id that is set to last for months on the users computer. This will let you see when people come back – as they will have different visitor ids, yet the longer lasting id will be the same as long as they didn’t delete the cookie.


Edited by s a m on Monday 5th June 00:12

_dobbo_

14,619 posts

278 months

Monday 5th June 2006
quotequote all
It doesn't need to be a php tracker - as long as your web server creates W3C compliant log files you can use any number of log file analysis tools. I've used "weblog expert" which is pretty good, and can monitor entry, exit and pathways through your site. There is a free version as well.

Otherwise get signed up for google analytics, it's pretty groovy.

Google Analytics:




Weblog Expert:

r988

7,498 posts

259 months

Monday 5th June 2006
quotequote all
another vote for google analytics, it's pretty easy to use and looks nice, with lots of pretty charts and maps to impress the boss

victormeldrew

8,293 posts

307 months

Monday 5th June 2006
quotequote all
r988 said:
another vote for google analytics, it's pretty easy to use and looks nice, with lots of pretty charts and maps to impress the boss
[sad geeky nerd]Pretty charts using Dundas Charts if I'm not mistaken.[/sad geeky nerd]

JonRB

80,093 posts

302 months

Monday 5th June 2006
quotequote all
If your host is using Apache, then Webalizer is free and easy, although I can't comment on whether or not it would be sufficient for your needs.