[ic] View-Counter UserTag?

Mike Heins mike at perusion.com
Mon Jul 22 19:03:35 UTC 2013


Quoting Mike Heins (mike at perusion.com):
> Quoting Iserv-appbox (ibox23 at iserv.xs4all.nl):
> > Hi,
> > 
> > I'm looking for a "View-Counter" UserTag in Interchange.
> > 
> > We are in the process of tranferring our website to Interchange.
> > I'm stumbling over an issue however.
> > 
> > For our current website I programmed a simple perl script "counter.cgi"
> > that writes the IP address of the visitor to a log file each time it is invoked.
> > Via an <!--#include virtual=..--> we include this script into the page that we want to monitor.
> > 
> > In Interchange I can't find a comparable UserTag however.
> > I searched the Interchange coretags, UI, standard demo, CPAN, but no luck.
> > It seems there is no "central repository" of Interchange UserTag contributions.
> > 
> > Before I start coding myself..
> > Did anyone make such a UserTag?
> > 
> 
> <!-- [log file="logs/hits/@@MV_PAGE@@" create=1 interpolate=1][data session ohost]	[time fmt="%Y-%m-%d %H:%M:%S][/log] -->

Actually, besides missing a quote, that won't work unless the file already
exists. Creating such a thing is pretty easy:

UserTag  log-hits  Routine <<EOR
sub {
	my $page = $Tag->var('MV_PAGE', 1);
	my $fn = "logs/hits/$page";
	my $data = join "\t", $Session->{host}, $Tag->time({ fmt => '%Y-%m-%d %H:%M:%S'});
	if(-f $fn) {
		$Tag->log( { file => $fn }, $data);
	}	
	else {
		$data .= "\n";
		$Tag->write_relative_file( { file => $fn }, $data);
	}
	return;
}
EOR


Now you just need [log-hits] in any page, and away you go.

-- 
Mike Heins
Perusion -- Expert Interchange Consulting    http://www.perusion.com/
phone +1.765.253.4194  <mike at perusion.com>

{((>:o}~  <<<<Oh look!!! An idolatrous image of the prophet!!! Surely
we must now avenge this blasphemy by burning down the world!!!



More information about the interchange-users mailing list