[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • Last Modified:

Script to Count Links/Page Hits

Hello,

Looking for CGI code (probably in perl) that keeps a count of the number of times each page in site is accessed as well as the number of times the links on the pages are hit on a monthly basis broken down in hourly time intervals. Output continually updates a MMMLinkCount.txt file and MMMPageCount.txt report in ./data directory with | delimiter. These files then can be loaded into Excel for creating spreadsheets and graphics.

JanLinkCount.Txt:

Date|Time|Page|Link|# Link Hits
01-01-01|00:00-01:00|index.htm|faq|5
01-01-01|00:00-01:00|index.htm|guest book|7
etc.

JanPageCount.txt:

Date|Time|Page|Link|# Link Hits
01-01-01|00:00-01:00|index.htm|12
etc.

Thanks in advance

0
zipdog44
Asked:
zipdog44
  • 3
  • 3
1 Solution
 
bebonhamCommented:
perhaps your server can provide you with such information?

I know a program that parses your server logs could, because your server can log every hit to every page on your site...and the ip of the visitor...and date and time of course...
now all that is left is to get all the the hits from the same ip together, and then sort them by time...then by some tricky logic that will know what links are on each page (an array of arrays with that information) you will see if that person has followed a link or typed in a new url...

the only place such a program might fail is if the person type the url of a LINK on that page into the address bar...the program would assume that the browser followed the link, and didn't type that in...

the reason I am suggesting this is here.

doing a counter for each page is fine, that can happen on page load...but counting the links hits on each page presents a problem...all your links will have to mess with the cgi as well...or you will be using a good bit of javascript...either way...you are now making a cgi dependant on very specific html and javascript features...that you will have to add to every page...and every new page.

HOWEVER, it can definitely be done, and I already have the solution in mind, as I have done similar before...


for instance...we could change the src of a 1px by 1 px img to the script with a query string indicating what action (link, new page, etc) was taken by the browser.

I strongly suggest you look into parsing the web server log file...

that is your best bet to get the info, becuase then you won't bog your server with that extra traffic on EVERY page.

I also believe there is premade software avail. for this purpose, and I will see if I can find such.


which way to you want to progress?


Bob
0
 
zipdog44Author Commented:
Thanks for the link.

Some problems I see.

Using Apache web server on solaris.

Products seem geared to Microsoft.
None of the products seem to count number of
time a link is hit.

I think a new product needs development to
get this information what about u?. If interested
I would like to work with u on developing the product.
I think it could be a success?

Thanks
Tom
0
How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

 
zipdog44Author Commented:
Log file does not record link information but I found this solution in "Writing CGI Applications with Perl" by kevin Meltzer and Brent Michalski for keeping a count of links in a MySql database

Create table

CREATE TABLE click_tracker (

     PAGE varchar(255) NOT NULL,
     COUNT int(11) NOT NULL,
     LAST_ACCESS datetime
);


Script:

#!/usr/bin/perl ?wT
# track.cgi
use strict;
use DBI;
use CGI qw(:standard);
use POSIX;
my $dbname = 'tomatocans';
my $dbhost = 'localhost';
my $dsn = "DBI:mysql:database=$dbname;host=$dbhost";
my $dbh=DBI-connect($dsn,"tomatocans","nakedtest");
if (!defined($dbh)) {
     print header; print "\nerror: There is a problem connecting to the MySQL database:\n";
     print DBI-errmsg;
     print "-" x 25; exit;
}
my $url = param('url');
my $time = strftime("%Y-%m/-%d %I:%M:%S", localtime);
my $query = qq(update click_tracker set COUNT=COUNT+1, LAST_ACCESS='$time' where PAGE='$url');
my $sth = $dbh-prepare($query);
if ($sth->execute <1){
    $query == qq(insert into click_tracker(PAGE,COUNT,LAST_ACCESS) Values('$url', 1, '$time'));
    $sth =  $dbh->prepare($query);
    $sth-execute;
}
$dbh-disconnect;
print redirect($url);



0
 
zipdog44Author Commented:
Your answer helped raise more questions. See last comment to see how I am proposing to solve Link Count. Still need to solve page count but i did not get any response from you so I wanted to remove question for EE.

If u want to participate more actively in the solution please feel free to email me at tomatocans@aol.com


Thanks
0
 
bebonhamCommented:
I was on vaccation...

no problem, I will email you with some help!
as your question is interesting.


Regards,

Bob
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now