Skip to content

Commit 4f6eeb1

Browse files
committed
meta_data: show analytics about the type of browser visiting the website
1 parent 0be9eff commit 4f6eeb1

File tree

5 files changed

+72
-4
lines changed

5 files changed

+72
-4
lines changed

cgi-bin/page.fcgi

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ Log::WarnDie->dispatcher($logger);
9898
# use VWF::Display::editor;
9999
# use VWF::Display::meta_data;
100100

101-
use VWF::data::index;
101+
use VWF::Data::index;
102+
use VWF::Data::vwf_log;
102103

103104
my $database_dir = "$script_dir/../data";
104105
Database::Abstraction::init({
@@ -108,13 +109,16 @@ Database::Abstraction::init({
108109
logger => $logger
109110
});
110111

111-
my $index = VWF::data::index->new();
112+
my $index = VWF::Data::index->new();
112113
if($@) {
113114
$logger->error($@);
114115
Log::WarnDie->dispatcher(undef);
115116
die $@;
116117
}
117118

119+
# FIXME - support $config->vwflog();
120+
my $vwf_log = VWF::Data::vwf_log->new({ directory => $info->logdir(), filename => 'vwf.log', no_entry => 1 });
121+
118122
# http://www.fastcgi.com/docs/faq.html#PerlSignals
119123
my $requestcount = 0;
120124
my $handling_request = 0;
@@ -182,6 +186,7 @@ while($handling_request = ($request->Accept() >= 0)) {
182186
Log::WarnDie->dispatcher($logger);
183187
$index->set_logger($logger);
184188
$info->set_logger($logger);
189+
$vwf_log->set_logger($logger);
185190
# $Config::Auto::Debug = 1;
186191

187192
$Error::Debug = 1;
@@ -489,6 +494,7 @@ sub doit
489494
databasedir => $database_dir,
490495
database_dir => $database_dir,
491496
index => $index,
497+
vwf_log => $vwf_log,
492498
});
493499
if($vwflog && open(my $fout, '>>', $vwflog)) {
494500
print $fout

lib/VWF/Data/index.pm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package VWF::Data::index;
2+
3+
# The database associated with the index template file
4+
5+
use Database::Abstraction;
6+
7+
our @ISA = ('Database::Abstraction');
8+
9+
1;

lib/VWF/Data/vwf_log.pm

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package VWF::Data::vwf_log;
2+
3+
# Open /tmp/vwf.log as a database
4+
# Standard CSV file, with no header line
5+
6+
use strict;
7+
use warnings;
8+
9+
use Database::Abstraction;
10+
11+
our @ISA = ('Database::Abstraction');
12+
13+
# Doesn't ignore lines starting with '#' as it's not treated like a CSV file
14+
sub _open {
15+
my $self = shift;
16+
my %args = (ref($_[0]) eq 'HASH') ? %{$_[0]} : @_;
17+
18+
return $self->SUPER::_open(sep_char => ',', column_names => ['domain_name', 'time', 'IP', 'country', 'type', 'language', 'http_code', 'template', 'args', 'warnings', 'error'], %args);
19+
}
20+
21+
1;

lib/VWF/data/index.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package VWF::data::index;
1+
package VWF::Data::index;
22

33
# The database associated with the index template file
44

templates/default/web/VWF/Display/meta_data.tmpl

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,41 @@
1010
<meta name="object" content="Index">
1111
<meta name="owner" content="Nigel Horne">
1212
<meta name="Author" content="Nigel Horne">
13-
<meta name="Copyright" content="Copyright (C) 2025 Nigel Horne">
13+
<meta name="Copyright" content="Copyright (C) 2025 Nigel Hornne, all rights reserved">
1414
<title>[% SiteTitle %]: Meta Data</title>
1515
[% IF keywords %]
1616
<meta name="keywords" content="[% keywords %]" />
1717
[% END %]
1818
<link rel="stylesheet" type="text/css" href="/css/style.css" />
19+
[% IF datapoints %]
20+
<script>
21+
window.onload = function() {
22+
23+
var chart = new CanvasJS.Chart("chartContainer", {
24+
animationEnabled: true,
25+
title: {
26+
text: "Browser breakdown by type"
27+
},
28+
data: [{
29+
type: "pie",
30+
startAngle: 240,
31+
// yValueFormatString: "##0.00\"%\"",
32+
yValueFormatString: "##0",
33+
indexLabel: "{label} {y}",
34+
dataPoints: [
35+
[% datapoints %]
36+
]
37+
}]
38+
});
39+
chart.render();
40+
41+
}
42+
</script>
43+
[% END %]
1944
</head>
2045

2146
<body>
47+
<!-- Show basic information about this site -->
2248
[% IF info %]
2349
<H1>Info</H1>
2450
domain_name: [% info.domain_name() %]<br>
@@ -30,5 +56,11 @@
3056
requested_language: [% lingua.requested_language() %]<br>
3157
language_code_alpha2: [% lingua.language_code_alpha2() %]
3258
[% END %]
59+
<!-- Show information about visitors to the site -->
60+
<!-- Browser type -->
61+
[% IF datapoints %]
62+
<div id="chartContainer" style="height: 370px; width: 100%;"></div>
63+
<script src="https://cdn.canvasjs.com/canvasjs.min.js"></script>
64+
[% END %]
3365
</body>
3466
</html>

0 commit comments

Comments
 (0)