hi all,
I want to know that is there any way to know after which page an user is leaving the website.
So that I can track that page and work to improve the content of that page.
I am using PHP as backend code.
hi all,
I want to know that is there any way to know after which page an user is leaving the website.
So that I can track that page and work to improve the content of that page.
I am using PHP as backend code.
The easiest way would be to add Google Analytics to your site.
The harder way would be to create a session for every visitor, and store in the database the last visited page. This has no guarantee they left the site for a reason such as "I did not like it", they may have clicked on a link that you provided.
Not quite precise.
Just track all hits and use timeouts to separate continuous page visits from page leavings.
That's all
If you want to see which is the last page a user is visiting, you can do something like this
I am assuming that you have a mysql connection already provided. Create a page like "session.php" and place this function
function trackpage($pagename) {
if(!isset($_SESSION)) {
// if the user is visiting the website for the first time
session_start();
$query = "INSERT INTO `newusers` VALUES(NULL, '$pagename');";
//In case table 'newuser' have two fields 'id' and 'page' to keep a track of page
$result = mysql_query($query) or die(mysql_error());
$_SESSION['userid'] = mysql_insert_id();
}
else {
//if he is just visiting another page
$query = "UPDATE `newusers` SET page='$pagename' WHERE id='".$_SESSION['userid']."';";
$result = mysql_query($query) or die(mysql_error());
}
}
Npw you need to include this on every page. on the top write this
<?
include "session.php";
trackpage("index.php");
?>
Now you know on what page are people leaving the website