Adding tracking by url.
This commit is contained in:
parent
5576215fd4
commit
31c7e569ec
@ -36,7 +36,8 @@ sub stats {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
my $data = $tracking->get_global_data($self);
|
my $data = $tracking->get_global_data($self);
|
||||||
$self->render(tracking_data => $data);
|
my $data_per_url = $tracking->get_data_for_urls($self);
|
||||||
|
$self->render(tracking_data => $data, tracking_by_url => $data_per_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub submit_login {
|
sub submit_login {
|
||||||
|
@ -6,11 +6,18 @@ use strict;
|
|||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
use JSON;
|
use JSON;
|
||||||
|
use Const::Fast;
|
||||||
|
|
||||||
use BurguillosInfo::DB;
|
use BurguillosInfo::DB;
|
||||||
|
|
||||||
my $app;
|
my $app;
|
||||||
|
|
||||||
|
const my $SELECT_GLOBAL => <<'EOF';
|
||||||
|
SELECT COUNT(DISTINCT (remote_address, user_agent))
|
||||||
|
FROM requests
|
||||||
|
EOF
|
||||||
|
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
$app = shift;
|
$app = shift;
|
||||||
@ -42,28 +49,55 @@ EOF
|
|||||||
my $c = shift;
|
my $c = shift;
|
||||||
my $app = $c->app;
|
my $app = $c->app;
|
||||||
my $dbh = BurguillosInfo::DB->connect($app);
|
my $dbh = BurguillosInfo::DB->connect($app);
|
||||||
my $data = $dbh->selectrow_hashref(<<'EOF', undef);
|
my $data = $dbh->selectrow_hashref(<<"EOF", undef);
|
||||||
SELECT
|
SELECT
|
||||||
(
|
(
|
||||||
SELECT COUNT(DISTINCT (remote_address, user_agent)) FROM requests
|
$SELECT_GLOBAL
|
||||||
) as unique_ips,
|
) as unique_ips,
|
||||||
(
|
(
|
||||||
SELECT COUNT(DISTINCT (remote_address, user_agent))
|
$SELECT_GLOBAL
|
||||||
FROM requests
|
|
||||||
where date > NOW() - interval '1 day'
|
where date > NOW() - interval '1 day'
|
||||||
) as unique_ips_last_24_hours,
|
) as unique_ips_last_24_hours,
|
||||||
(
|
(
|
||||||
SELECT COUNT(DISTINCT (remote_address, user_agent))
|
$SELECT_GLOBAL
|
||||||
FROM requests
|
|
||||||
where date > NOW() - interval '1 week'
|
where date > NOW() - interval '1 week'
|
||||||
) as unique_ips_last_week,
|
) as unique_ips_last_week,
|
||||||
(
|
(
|
||||||
SELECT COUNT(DISTINCT (remote_address, user_agent))
|
$SELECT_GLOBAL
|
||||||
FROM requests
|
|
||||||
where date > NOW() - interval '1 month'
|
where date > NOW() - interval '1 month'
|
||||||
) as unique_ips_last_month;
|
) as unique_ips_last_month;
|
||||||
|
|
||||||
|
|
||||||
|
EOF
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub get_data_for_urls {
|
||||||
|
my $self = shift;
|
||||||
|
my $c = shift;
|
||||||
|
my $app = $c->app;
|
||||||
|
my $dbh = BurguillosInfo::DB->connect($app);
|
||||||
|
my $data = $dbh->selectall_arrayref(<<"EOF", {Slice => {}});
|
||||||
|
SELECT paths.path,
|
||||||
|
(
|
||||||
|
$SELECT_GLOBAL
|
||||||
|
where requests.path = paths.path
|
||||||
|
) as unique_ips,
|
||||||
|
(
|
||||||
|
$SELECT_GLOBAL
|
||||||
|
where requests.path = paths.path and date > NOW() - interval '1 day'
|
||||||
|
) as unique_ips_last_24_hours,
|
||||||
|
(
|
||||||
|
$SELECT_GLOBAL
|
||||||
|
where requests.path = paths.path and date > NOW() - interval '1 week'
|
||||||
|
) as unique_ips_last_week,
|
||||||
|
(
|
||||||
|
$SELECT_GLOBAL
|
||||||
|
where requests.path = paths.path and date > NOW() - interval '1 month'
|
||||||
|
) as unique_ips_last_month
|
||||||
|
FROM paths;
|
||||||
|
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
@ -6,4 +6,20 @@
|
|||||||
<p>Unique visitors last 24 hours <%=$tracking_data->{unique_ips_last_24_hours}%></p>
|
<p>Unique visitors last 24 hours <%=$tracking_data->{unique_ips_last_24_hours}%></p>
|
||||||
<p>Unique visitors last week <%=$tracking_data->{unique_ips_last_week}%></p>
|
<p>Unique visitors last week <%=$tracking_data->{unique_ips_last_week}%></p>
|
||||||
<p>Unique visitors last month <%=$tracking_data->{unique_ips_last_month}%></p>
|
<p>Unique visitors last month <%=$tracking_data->{unique_ips_last_month}%></p>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>Path</th>
|
||||||
|
<th>Visitors 24h</th>
|
||||||
|
<th>Visitors week</th>
|
||||||
|
<th>Visitors month</th>
|
||||||
|
</tr>
|
||||||
|
% for my $row (@$tracking_by_url) {
|
||||||
|
<tr>
|
||||||
|
<td><%=$row->{path}%></td>
|
||||||
|
<td><%=$row->{unique_ips_last_24_hours}%></td>
|
||||||
|
<td><%=$row->{unique_ips_last_week}%></td>
|
||||||
|
<td><%=$row->{unique_ips_last_month}%></td>
|
||||||
|
</tr>
|
||||||
|
%}
|
||||||
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user