Forum Moderators: coopster

Message Too Old, No Replies

How to track session of visitors and ads?

         

toplisek

7:12 pm on Mar 1, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



How to track session of visitors (time of visits at particular page) and show ads if visitor clicks on defined link at URL and/or session comes within particular time?
Is there some the best professional PHP script to manage this with support of PHP and database?

eelixduppy

9:48 pm on Mar 1, 2010 (gmt 0)



I'm not sure of any scripts that do this automatically out of the box, however, it shouldn't be that difficult to write yourself if you are willing to learn.

CyBerAliEn

10:10 pm on Mar 1, 2010 (gmt 0)

10+ Year Member



^ agree with eelixduppy

You could do something~ like you want with simple code like:
<?php
session_start();
if ($_SESSION['tracking']['set']===true)
{
//Update Tracking
$_SESSION['tracking']['last'] = $_SESSION['tracking']['current'];
$_SESSION['tracking']['lastREQ'] = $_SESSION['tracking']['REQ'];
$_SESSION['tracking']['current'] = time();
$_SESSION['tracking']['REQ'] = $_SERVER['REQUEST_URI'];
}
else
{
//Setup New Tracking
$_SESSION['tracking']['set'] = true;
$_SESSION['tracking']['current'] = time();
$_SESSION['tracking']['REQ'] = $_SERVER['REQUEST_URI'];
$_SESSION['tracking']['last'] = 0;
$_SESSION['tracking']['lastREQ'] = '';
}
?>


Is this what you want? Maybe. lol.

Just add the code to the top of all your pages/etc. It will automatically start storing basic "tracking" info in the PHP session. Specifically, the currently requested URI (ie: /gallery/view.php?item=343) and the UNIX timestamp. It will also hold onto the "last" values so you know the last time they accessed the site and the last URI they requested.

Else where in your site, you could have your other scripts access this data to determine display of your ads/etc.

If you wanted it to be more robust in terms of tracking ALL the URIs they visit or ALL the timestamps of each visit, you could do this by modifying the code and setting each of the main keys as ARRAYS and then loading new items onto the end of the arrays. This would keep a running log of requests and request times in the PHP session. A la:

$_SESSION['tracking']['requests'][] = $_SERVER['REQUEST_URI'];
_$SESSION['tracking']['times'][] = time();


^ This would create a running log of requests and their times. You could then combine/check them against your desired ad scripting/etc.

Hope that can help you get on with what you want.


End note: You should be prepared to put a cap limit on the number of entries that will get logged. IE: remove oldest entry when 20 items get logged. Etc. Why? A busy site with lots of visitors will create a lot of session data on your server, and if this tracking is allowed to go unlimited, it will waste a lot of disk space without any real benefit.

adamflaier

3:57 pm on Apr 22, 2010 (gmt 0)

10+ Year Member



Just thought I'd join in the conversation-- I don't know much about PHP myself so I would rely on web-based services for minor yet essential tasks such as this. I use a 3rd party for tracking company visitors to my site and have been very proud with the results of the site. If you don't have time to play around with PHP scripting (such as myself), I suggest you try this site

[edited by: jatar_k at 4:06 pm (utc) on Apr 22, 2010]
[edit reason] no urls thanks [/edit]