Solved

Script to Count Links/Page Hits

Posted on 2001-06-29
6
223 Views
Last Modified: 2013-12-25
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
Comment
Question by:zipdog44
  • 3
  • 3
6 Comments
 
LVL 8

Accepted Solution

by:
bebonham earned 200 total points
ID: 6239867
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
 
LVL 8

Expert Comment

by:bebonham
ID: 6239883
0
 

Author Comment

by:zipdog44
ID: 6240881
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:zipdog44
ID: 6250267
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
 

Author Comment

by:zipdog44
ID: 6250278
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
 
LVL 8

Expert Comment

by:bebonham
ID: 6254128
I was on vaccation...

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


Regards,

Bob
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
disabled AD accounts info 3 75
Editing Powershell script to resolve DNS from HashTable ? 7 59
Folder Permission Powershell 4 57
AutoHotkey ActiveX Component Error 8 86
If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question