[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Script to Count Links/Page Hits

Posted on 2001-06-29
6
Medium Priority
?
254 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 8

Accepted Solution

by:
bebonham earned 600 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
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.

 

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

656 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