Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Record Page Views for Categories

Quote Reply
Record Page Views for Categories
Hi-

Does anyone know if there would be a way to record the number of times an individual category page is viewed? Using our existing log analysis software it is a cumbersome process because we have so many different categories.

In other words, would there be a way to put some type of script on a category page that when the page is viewed would increment a field called Page_Views for that specific category in the categories database?

-jw
Quote Reply
Re: [jwalter] Record Page Views for Categories In reply to
If you use page.cgi, you can easily add a sub that updates a column called something like CatHits in the Category table:

1) Add a column called CatHits in the Category table (via MySQLMan) -> This should be either an INT or SMALLINT data type field, use the following attributes:

Data Type: INT (or SMALLINT)
Null
Default Value: 0

2) Then add a sub that includes the following SQL (or add a global tag that includes the SQL):

Code:

Update Category
SET CatHits = CatHits + 1
WHERE CategoryID = $catid


Of course you would have define $catid as the category id that the user is in at the time the table is updated.

Best of luck...
========================================
Buh Bye!

Cheers,
Me

Last edited by:

Chewbaca: Nov 2, 2001, 10:59 AM
Quote Reply
Re: [Chewbaca] Record Page Views for Categories In reply to
Thanks very much Eliot. I'm not very proficient in PERL, but you've kindly provided all of the basics, so I'll try experimenting with that to see if I can get it to work.

-jw
Quote Reply
Re: [jwalter] Record Page Views for Categories In reply to
You're welcome.

NOTE: I edited my original reply to include some hints on adding the Column in the Category table.
========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [jwalter] Record Page Views for Categories In reply to
A global to do the job would be:

update_category_hits =>
Code:
sub {
my $tags = shift;
my $cid = $tags->{category_id} or return "No category ID found on this page!";
my $table = $DB->table('Category');
$table->update ( { CatHits => \'CatHits + 1' }, { ID => $cid });
return;
}

and then just put <%update_category_hits%> on your category.html template. This assumes you have added a field called CatHits to your category table, and that you are using page.cgi.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Record Page Views for Categories In reply to
Thanks very much Alex and Eliot. Your help is much appreciated ! Smile

-jw