Forum Moderators: coopster

Message Too Old, No Replies

Tracking Question

         

woldie

11:49 am on May 6, 2004 (gmt 0)

10+ Year Member



Hi,

I've got a requirement from a client about tracking. What I would like to do is when someone clicks on a button, I want to track that click in place that into the DB.

Essentially when you do click on the button a JavaScript window opens which is called contact.html for example.

Any good ways of overcoming this?

Thanks

httpwebwitch

2:10 pm on May 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My favourite method - assuming you have a database handy - is to create a gateway page that does the database interaction, then passes the user to the desired link.

click on the button, and instead of opening "contact.html", open "tracker.php?goto=contact.html"

the file "tracker.php" contains some SQL commands that writes to the database, but has no output and just passes the person along with header():

$query="INSERT INTO mytable (URL,Datetime) VALUES ($HTTP_GET_VARS['goto'],date("Y-m-d h:i:s",mktime()))";
mysql_query($query);
header('Location:'.$HTTP_GET_VARS['goto']);

You can also store the Referrer page, the remote_address (user IP), and any other statistics about the situation that your server can see and you might be curious about. The table then contains a record of each click, with the date/time, what page the person was clicking to, etc. The one table can be used to track clicks to any number of pages, and the statistics can be gleaned with a simple SQL SELECT.

Good luck!

woldie

2:19 pm on May 6, 2004 (gmt 0)

10+ Year Member



Good Skillz httpwebwitch,

I will certainly opt for that method, that is a cool method for sure.

Thanks for your help

woldie

2:36 pm on May 6, 2004 (gmt 0)

10+ Year Member



I see you have Datetime as a field in the DB, can you tell me what field type you specified it as i.e. timestamp,date etc...

Thanks

httpwebwitch

3:12 pm on May 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



in Mysql, you could use data type "timestamp", which just stamps the time when the record is created/modified (I'm actually not so sure about its behaviour). With that type you don't even need to write anything in there, it defaults and fills itself in. If you like that, experiment with it.

Instead, I prefer the data type "datetime", where I explicitly write the date and time in format
YYYY-mm-dd hh:mm:ss

I feel like it gives me more control, and it behaves just like a string, in an obvious predictable way.

httpwebwitch

3:19 pm on May 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oh, sorry I didn't mention this: make sure your table has a unique autoincrementing primary key. It's very likely that the same page might be requested twice within one second, giving you 2 identical rows (& that's a nono)

You don't have to change the SQL INSERT command, as long as the field is there in the Table you're OK.