derekovecs: log all queries via Matomo
diff --git a/w2v-server.pl b/w2v-server.pl
index 7073183..ef80bf0 100755
--- a/w2v-server.pl
+++ b/w2v-server.pl
@@ -13,6 +13,15 @@
app->static->paths->[0] = getcwd;
+plugin Config => {file => 'w2v-server.conf'};
+plugin 'Piwik';
+plugin 'Util::RandomString' => {
+ piwik_rand_id => {
+ alphabet => '0123456789abcdef',
+ length => 16
+ }
+};
+
plugin 'Log::Access';
plugin "RequestBase";
#plugin 'AutoReload';
@@ -99,7 +108,7 @@
$url =~ s@/derekovecs@@g;
$c->app->log->info("GET: " . $url);
$c->reply->static($url);
-};
+} => 'js';
get '*/css/*' => sub {
my $c = shift;
@@ -107,7 +116,7 @@
$url =~ s@/derekovecs/@/@g;
$c->app->log->info("GET: " . $url);
$c->reply->static($url);
-};
+} => 'css';
sub fname2corpusname {
($_) = @_;
@@ -193,22 +202,22 @@
any '*/getClassicCollocators' => sub {
my $self = shift;
$self->render(data => getClassicCollocatorsCached($self, getWord($self->param("w") ? $self->param("w") : $self->req->json)), format=>'json');
-};
+} => 'getClassicCollocators1';
any '/getClassicCollocators' => sub {
my $self = shift;
$self->render(data => getClassicCollocatorsCached($self, getWord($self->param("w") ? $self->param("w") : $self->req->json)), format=>'json');
-};
+} => 'getClassicCollocators';
any '/getBiggestVocabDistances' => sub {
my $self = shift;
$self->render(data => getBiggestMergedDifferences(), format=>'json');
-};
+} => 'getBiggestVocabDistances1';
any '*/getBiggestVocabDistances' => sub {
my $self = shift;
$self->render(data => getBiggestMergedDifferences(), format=>'json');
-};
+} => 'getBiggestVocabDistances';
any '*/getPosWiseW2VCollocators' => sub {
my $self = shift;
@@ -331,7 +340,7 @@
}
$c->render(template=>"index", title=>$title, word=>$word, distantWords=>$distantWords, cutoff=>$cutoff, no_nbs=>$no_nbs, no_iterations => $no_iterations, epsilon=> $epsilon, perplexity=> $perplexity, show_som=>$som, searchBaseVocabFirst=>$searchBaseVocabFirst, sort=>$sort, training_args=>$training_args, mergedEnd=> $mergedEnd, haveSProfiles=> $have_sprofiles, dedupe=> $dedupe, marked=>\%marked, lists=> \@lists, collocators=> $res->{syntagmatic});
}
-};
+} => "paradigmaticAndSyntagmaticNbs";
helper(bitvec2window => sub {
my ($self, $n) = @_;
@@ -343,6 +352,31 @@
return $str;
});
+hook(
+ after_render => sub {
+ my $c = shift;
+
+ # Only track valid routes
+ my $route = $c->current_route or return;
+
+ # This won't forward personalized information
+ my $hash = {
+ action_url => $c->url_for->to_abs,
+ action_name => $route,
+ ua => '',
+ urlref => '',
+ send_image => 0,
+ dnt => 0,
+ uid => $c->random_string('piwik_rand_id')
+ };
+ $c->app->log->info("PIWIK: counting " . $hash->{action_url});
+ $c->app->log->info("PIWIK: tag " . $c->piwik_tag);
+
+ # Send track
+ $c->piwik->api_p(Track => $hash)->wait;
+ }
+);
+
$daemon->run;
# app->start;