Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Bump hit counter > file downloads?

Quote Reply
Bump hit counter > file downloads?
I see in this post:

http://gossamer-threads.com/...orum.cgi?post=207031

there's a suggested way to bump the hit counter for file downloads which involves setting up a new colum in the links table and building a new Perl script to track this.

The way my sites setup ill only be tracking either hits out to URL or hits to downloaded files.

Can someone suggest a way to modify the Jump.pm to enable bumping the Hits counter for files?

here's what i've got:

Code:
# Find out if we're going to be displaying a file
my $col = $IN->param('v') || $IN->param('dl') || $IN->param('view') || $IN->param('download');

# in this case, we need to know from what table we want to load our data from.
# It will by default pull information from the Links table, however if the
# DB=tablename option is used, it will apply the request to that table instead
my $table_name = $IN->param( 'DB' ) || 'Links';

unless ( $table_name =~ m,^\w+$, ) {
require Links::SiteHTML;
print $IN->header();
print Links::SiteHTML::display('error', { error => Links::language('FILE_TABLEFORMAT' ) });
return;
};

if ( $table_name ne 'Links' ) {
eval { $db = $DB->table( $table_name ) };
if ( $@ ) {
require Links::SiteHTML;
print $IN->header();
print Links::SiteHTML::display('error', { error => Links::language('FILE_TABLE', $table_name, $GT::SQL::error ) });
return;
}
}

if ($col) {
my $fh;
eval { $fh = $db->file_info( $col, $id ); };
if ( $fh ) {
if ($IN->param('v') or $IN->param('view')) { # Viewing
print $IN->header(
'-type' => $fh->File_MimeType,
'-Content-Length' => $fh->File_Size,
'-Content-Disposition' => \("inline; filename=" . $IN->escape($fh->File_Name))
);
}
else { # Downloading
print $IN->header(
'-type' => 'application/download',
'-Content-Length' => $fh->File_Size,
'-Content-Transfer-Encoding' => 'binary',
'-Content-Disposition' => \("attachment; filename=" . $IN->escape($fh->File_Name))
);
}
binmode $fh;
while (read ($fh, my $buffer, 65536)) {
print $buffer;
}
return 1;
}
else {
require Links::SiteHTML;
print $IN->header();
print Links::SiteHTML::display('error', { error => Links::language('FILE_UNKNOWN', $id) });
return;
}
}

and track hits to url:

Code:
# Jump to a URL, bump the hit counter.
else {
$goto = $rec->{URL};

my $ip = $ENV{REMOTE_HOST} || $ENV{REMOTE_ADDR} || 'None';
my $click_db = $DB->table ('ClickTrack');
my $rows = $click_db->count ( { LinkID => $id, IP => $ip, ClickType => 'Hits' } );
if (! $rows) {
$db->update ( { Hits => \"Hits + 1" }, { ID => $id }, { GT_SQL_SKIP_INDEX => 1 } );
$click_db->insert ( { LinkID => $id, IP => $ip, ClickType => 'Hits', Created => \"NOW()"} );
}
}
}


Thanks in advance for your help :)
Quote Reply
Re: [Chas-a] Bump hit counter > file downloads? In reply to
You'll just need to add the bit which updates the hits into the section which does the downloads.

Copy

my $ip1 = $ENV{REMOTE_HOST} || $ENV{REMOTE_ADDR} || 'None';
my $click_db1 = $DB->table ('ClickTrack');
my $rows1 = $click_db1->count ( { LinkID => $id, IP => $ip1, ClickType => 'Hits' } );
if (! $rows1) {
$db->update ( { Hits => \"Hits + 1" }, { ID => $id }, { GT_SQL_SKIP_INDEX => 1 } );
$click_db1->insert ( { LinkID => $id, IP => $ip1, ClickType => 'Hits', Created => \"NOW()"} );
}

Into the previous section. I think the best place is probably just before the line

return 1;
Quote Reply
Re: [afinlr] Bump hit counter > file downloads? In reply to
Works a charm Wink

thanks Laura!