You are here:  » Recording what category is clicked on

Active Forum Topics


Recording what category is clicked on

Submitted by bem on Tue, 2015-09-22 12:59 in

Hi David ,

Is there a way to easily record which category is selected via the category page? On an older site I had a method, but it recorded a hit every time someone went to the next page in the category as well, so one person looking at one category got counted as 9 as they were just casually browsing though the product list, which then made the category look more popular to me that it actually was.

Thanks
Ben

Submitted by support on Tue, 2015-09-22 13:59

Hello Ben,

If you still have the code it should just be case of adding a text for $page==1 to the IF condition surrounding the logging code - probably:

if ($parts[0]=="category"])
{
  // code to log click to category in $parts[1] here
}

...so if you extended the test as follows;

if (($parts[0]=="category"]) && ($page==1))
{
  // code to log click to category in $parts[1] here
}

If you no longer have the code, let me know how / where it was performing the logging and I'll re-work it for you...

Cheers,
David.
--
PriceTapestry.com

Submitted by bem on Tue, 2015-09-22 14:06

Hi David ,

Cheers. Unfortunately I don't have the code any more, it was about 2 years ago and because I couldn't get it working how I wanted I didn't bother keeping that part when I updated.

Thanks
Ben

Submitted by support on Tue, 2015-09-22 14:36

Hello Ben.

Virtually everything is in place to achieve this in the recently documented query logging / popular searches mod in this thread. So that would make a good starting point. Create and run the dbmod.php script to create the `querylog` table, however in place of first REPLACEment for search.php, use instead:

    require("html/searchresults.php");
    if (($parts[0]=="category"]) && ($page==1))
    {
      $sql = "INSERT INTO `".$config_databaseTablePrefix."querylog`
                SET query='".database_safe($q)."'
                  ON DUPLICATE KEY UPDATE count = count + 1";
      database_queryModify($sql,$result);
    }

Then you can make an admin/top10categories.php as follows:

<?php
  
require("../includes/common.php");
  
$admin_checkPassword TRUE;
  require(
"admin_header.php");
  print 
"<h2>Top 10</h2>";
  print 
"<h3>Categories</h3>";
  
$sql "SELECT * FROM `".$config_databaseTablePrefix."querylog` WHERE query LIKE 'category:%' ORDER BY count DESC LIMIT 10";
  if (
database_querySelect($sql,$rows))
  {
    print 
"<table>";
    foreach(
$rows as $querylog)
    {
      
$parts explode(":",$querylog["query"]);
      print 
"<tr>";
      print 
"<td>".$querylog["count"]."</td>";
      print 
"<td><a href='".$config_baseHREF."search.php?q=".urlencode($querylog["query"])."'>".$parts[1]."</a></td>";
      print 
"</tr>";
    }
    print 
"</table>";
  }
  else
  {
    print 
"<p>There are no searches to display.</p>";
  }
  require(
"admin_footer.php");
?>

I've intentionally used a WHERE clause in the above so that you can easily extend this to full query logging in the future if you wished, and still use the above script to display only top categories. You can change the LIMIT as required, or remove completely from the SQL to display all category log entries.

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by bem on Thu, 2015-09-24 08:41

HI David ,

Sorry for the late reply. Cheers for that. All works well. Much appreciated.

Thanks
Ben