Solved

Script to Count Links/Page Hits

Posted on 2001-06-29
6
232 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 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What is assert.deepEqual? 4 59
Remote Exchange powershell returns different results 13 50
Error when Running powershell script 6 31
Ruby or Python 7 63
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 …
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
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 …

730 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