You are here:  » Clicks daily

Active Forum Topics


Clicks daily

Submitted by MarcoCH on Sat, 2019-02-02 13:47 in

Hello

I would like to save the daily clicks in a .txt file or admin area, is that possible?

Thanks and regards
Marco

Submitted by support on Mon, 2019-02-04 10:06

Hi Marco,

Sure - if you don't mind the clicks being reset to zero daily it's no problem to log the clicks per feed to a file. If you create the following as scripts/clicks.php

<?php
  
require("../includes/common.php");
  
$fp fopen($config_feedDirectory."clicks_".date("Y-m-d").".txt","w");
  
$sql "SELECT filename,clicks FROM `".$config_databaseTablePrefix."feeds`";
  
database_querySelect($sql,$feeds);
  foreach(
$feeds as $feed)
  {
    
fwrite($fp,$feed["filename"].",".$feed["clicks"]."\n");
  }
  
fclose($fp);
  
$sql "UPDATE `".$config_databaseTablePrefix."feeds` SET clicks='0'";
  
database_queryModify($sql,$result);
?>

...and then schedule that to run as a cronjob as close to midnight as possible (but not at or over) and this will output the daily clicks to a file in the feeds directory for example:

clicks_2019-02-04.txt

I've used the feeds directory is it would normally be set-up to be writeable by PHP but if you'd prefer to use an alternative location just replace $config_feedDirectory with an appropriate path e.g.

  $fp = fopen("clicks/clicks_".date("Y-m-d").".txt","w");

...which in this case would be a clicks/ sub-directory of the scripts folder.

Make sure that the location is writable by PHP (set to the same mode as the feeds/ folders), and when setting up your cronjob, don't forget to include a cd command so that the relative location can be found just as for cron.php e.g.

cd /home/username/public_html/scripts/;/usr/bin/php clicks.php

Cheers,
David.
--
PriceTapestry.com

Submitted by MarcoCH on Fri, 2019-02-08 19:57

Hello

Thank you for the help, works so far.
Can I spend the last 10 maybe on the admin page.
So I see a big change.

regards
Marco

Submitted by support on Sat, 2019-02-09 12:04

Hi Marco,

To add last 10 days clicks to admin home page, edit admin/index.php and look for the following code at line 244:

  require("admin_footer.php");

...and REPLACE with:

  $clicks = array();
  $date = time();
  for($i=1;$i<=10;$i++)
  {
    $date -= 86400;
    $filename = $config_feedDirectory."clicks_".date("Y-m-d",$date).".txt";
    $heading = date("m-d",$date);
    if (file_exists($filename))
    {
      $fp = fopen($filename,"r");
      while($row = fgetcsv($fp))
      {
        $feed = $row[0];
        $clicks[$feed][$heading] = $row[1];
      }
    }
  }
  print "<table>";
  print "<tr>";
  print "<th>&nbsp;</th>";
  foreach($clicks[$feed] as $heading => $v)
  {
    print "<th>".$heading."</th>";
  }
  print "</tr>";
  foreach($clicks as $feed => $row)
  {
    print "<tr>";
    print "<th class='pta_key'>".$feed."</th>";
    foreach($row as $v)
    {
      print "<td class='pta_num'>".$v."</td>";
    }
    print "</tr>";
  }
  print "</table>";
  require("admin_footer.php");

(if you're saving clicks to a directory other than the feed directory make the same change to $config_feedDirectory in line 5 of the above replacement as in the clicks.php script)

Cheers,
David.
--
PriceTapestry.com