Fixed paths overflowing table on tracking page and made links clickable.

This commit is contained in:
Marvin Blum
2020-08-14 00:32:55 +02:00
committed by Marvin Blum
parent ab8123a4f7
commit 940395f9e4
7 changed files with 34 additions and 18 deletions

2
go.mod
View File

@@ -7,7 +7,7 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emvi/api-go v0.2.2
github.com/emvi/logbuch v1.1.1
github.com/emvi/pirsch v1.3.1
github.com/emvi/pirsch v1.3.2
github.com/go-sql-driver/mysql v1.5.0 // indirect
github.com/gorilla/mux v1.7.4
github.com/gosimple/slug v1.9.0

2
go.sum
View File

@@ -13,6 +13,8 @@ github.com/emvi/pirsch v1.3.0 h1:csgIvQKMMWF9EG4Dkfd4dFux6kfzOFC8PuNPWvsj7zM=
github.com/emvi/pirsch v1.3.0/go.mod h1:GDijqLHM331iWtmDmc7th19RxDrZadRkKoNvd9/kDX8=
github.com/emvi/pirsch v1.3.1 h1:K4+VonszJvZqtM7bQz8ZFZJJjQ8jlH/h6S/JiBpNQE8=
github.com/emvi/pirsch v1.3.1/go.mod h1:GDijqLHM331iWtmDmc7th19RxDrZadRkKoNvd9/kDX8=
github.com/emvi/pirsch v1.3.2 h1:CZCLO2OaWpA/eDdlg8xFo9yZMB9S71iyox54AVVwadU=
github.com/emvi/pirsch v1.3.2/go.mod h1:GDijqLHM331iWtmDmc7th19RxDrZadRkKoNvd9/kDX8=
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=

View File

@@ -156,7 +156,7 @@ func serveTracking() http.HandlerFunc {
PageVisits []tracking.PageVisits
Pages []pirsch.VisitorPage
Languages []pirsch.VisitorLanguage
Referer []pirsch.VisitorReferer
Referrer []pirsch.VisitorReferrer
HourlyVisitorsLabels template.JS
HourlyVisitorsDps template.JS
HourlyVisitorsTodayLabels template.JS
@@ -172,7 +172,7 @@ func serveTracking() http.HandlerFunc {
tracking.GetPageVisits(startDate, endDate),
tracking.GetPages(startDate, endDate),
tracking.GetLanguages(startDate, endDate),
tracking.GetReferer(startDate, endDate),
tracking.GetReferrer(startDate, endDate),
hourlyVisitorsLabels,
hourlyVisitorsDps,
hourlyVisitorsTodayLabels,

View File

@@ -88,6 +88,10 @@ body {
margin: 10px 0 0 0;
}
.break-line-anywhere {
line-break: anywhere;
}
input {
padding: 2px;
}

View File

@@ -41,7 +41,9 @@
<tbody>
{{range $data := .ActiveVisitorPages}}
<tr>
<td>{{$data.Path}}</td>
<td class="break-line-anywhere">
<a href="{{$data.Path}}" target="_blank">{{$data.Path}}</a>
</td>
<td>{{$data.Visitors}}</td>
</tr>
{{end}}
@@ -74,7 +76,9 @@
<tbody>
{{range $data := .Pages}}
<tr>
<td>{{$data.Path}}</td>
<td class="break-line-anywhere">
<a href="{{$data.Path}}" target="_blank">{{$data.Path}}</a>
</td>
<td>{{$data.Visitors}}</td>
</tr>
{{end}}
@@ -106,21 +110,27 @@
</table>
</section>
<section>
<h2>Referer</h2>
<h2>Referrer</h2>
<p>
Here are the top 10 referer.
Here are the top 10 referrer.
</p>
<table>
<thead>
<tr>
<th>Referer</th>
<th>Referrer</th>
<th>Visitors</th>
</tr>
</thead>
<tbody>
{{range $data := .Referer}}
{{range $data := .Referrer}}
<tr>
<td>{{if $data.Referer}}{{$data.Referer}}{{else}}(unknown){{end}}</td>
<td class="break-line-anywhere">
{{if $data.Referrer}}
<a href="{{$data.Referrer}}" target="_blank">{{$data.Referrer}}</a>
{{else}}
(unknown)
{{end}}
</td>
<td>{{$data.Visitors}}</td>
</tr>
{{end}}

View File

@@ -78,19 +78,19 @@ func GetLanguages(startDate, endDate time.Time) []pirsch.VisitorLanguage {
return languages
}
func GetReferer(startDate, endDate time.Time) []pirsch.VisitorReferer {
referer, err := analyzer.Referer(&pirsch.Filter{From: startDate, To: endDate})
func GetReferrer(startDate, endDate time.Time) []pirsch.VisitorReferrer {
referrer, err := analyzer.Referrer(&pirsch.Filter{From: startDate, To: endDate})
if err != nil {
logbuch.Error("Error reading referer statistics", logbuch.Fields{"err": err})
logbuch.Error("Error reading referrer statistics", logbuch.Fields{"err": err})
return nil
}
if len(referer) > 10 {
return referer[:10]
if len(referrer) > 10 {
return referrer[:10]
}
return referer
return referrer
}
func GetHourlyVisitors(startDate, endDate time.Time) (template.JS, template.JS) {

View File

@@ -51,8 +51,8 @@ func NewTracker() (*pirsch.Tracker, context.CancelFunc) {
store = pirsch.NewPostgresStore(conn)
tracker := pirsch.NewTracker(store, os.Getenv("MB_TRACKING_SALT"), &pirsch.TrackerConfig{
// I don't care about traffic from my own website
RefererDomainBlacklist: []string{domain},
RefererDomainBlacklistIncludesSubdomains: true,
ReferrerDomainBlacklist: []string{domain},
ReferrerDomainBlacklistIncludesSubdomains: true,
})
analyzer = pirsch.NewAnalyzer(store)
processor := pirsch.NewProcessor(store, nil)