mirror of
https://github.com/Kugelschieber/marvinblum.git
synced 2026-01-18 06:40:27 +00:00
Added active pages, visitor count per page and referer.
This commit is contained in:
2
go.mod
2
go.mod
@@ -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.0
|
||||
github.com/emvi/pirsch v1.3.1
|
||||
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
2
go.sum
@@ -11,6 +11,8 @@ github.com/emvi/pirsch v1.2.0 h1:k5OJwgE8/Zdq7raQNRF4aNHxWxPq7En51gWMMEFzinA=
|
||||
github.com/emvi/pirsch v1.2.0/go.mod h1:GDijqLHM331iWtmDmc7th19RxDrZadRkKoNvd9/kDX8=
|
||||
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/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=
|
||||
|
||||
6
main.go
6
main.go
@@ -154,12 +154,15 @@ func serveTracking() http.HandlerFunc {
|
||||
TotalVisitorsLabels template.JS
|
||||
TotalVisitorsDps template.JS
|
||||
PageVisits []tracking.PageVisits
|
||||
Pages []pirsch.VisitorPage
|
||||
Languages []pirsch.VisitorLanguage
|
||||
Referer []pirsch.VisitorReferer
|
||||
HourlyVisitorsLabels template.JS
|
||||
HourlyVisitorsDps template.JS
|
||||
HourlyVisitorsTodayLabels template.JS
|
||||
HourlyVisitorsTodayDps template.JS
|
||||
ActiveVisitors int
|
||||
ActiveVisitorPages []pirsch.PageVisitors
|
||||
}{
|
||||
start,
|
||||
startDate,
|
||||
@@ -167,12 +170,15 @@ func serveTracking() http.HandlerFunc {
|
||||
totalVisitorsLabels,
|
||||
totalVisitorsDps,
|
||||
tracking.GetPageVisits(startDate, endDate),
|
||||
tracking.GetPages(startDate, endDate),
|
||||
tracking.GetLanguages(startDate, endDate),
|
||||
tracking.GetReferer(startDate, endDate),
|
||||
hourlyVisitorsLabels,
|
||||
hourlyVisitorsDps,
|
||||
hourlyVisitorsTodayLabels,
|
||||
hourlyVisitorsTodayDps,
|
||||
tracking.GetActiveVisitors(),
|
||||
tracking.GetActiveVisitorPages(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,25 @@
|
||||
The next diagram shows active visitors for each hour of today.
|
||||
</p>
|
||||
<canvas id="hourlyVisitorsToday" class="tracking"></canvas>
|
||||
<p>
|
||||
The next table shows where the active visitors are for the past 30 seconds. Visitors switching between pages fast do create duplicate entries in the table.
|
||||
</p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Path</th>
|
||||
<th>Visitors</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{range $data := .ActiveVisitorPages}}
|
||||
<tr>
|
||||
<td>{{$data.Path}}</td>
|
||||
<td>{{$data.Visitors}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
<section>
|
||||
<h2>Total Visitors</h2>
|
||||
@@ -40,6 +59,28 @@
|
||||
</p>
|
||||
<canvas id="hourlyVisitors" class="tracking"></canvas>
|
||||
</section>
|
||||
<section>
|
||||
<h2>Pages</h2>
|
||||
<p>
|
||||
Here are the top 10 visited pages.
|
||||
</p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Path</th>
|
||||
<th>Visitors</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{range $data := .Pages}}
|
||||
<tr>
|
||||
<td>{{$data.Path}}</td>
|
||||
<td>{{$data.Visitors}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
<section>
|
||||
<h2>Languages</h2>
|
||||
<p>
|
||||
@@ -64,6 +105,28 @@
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
<section>
|
||||
<h2>Referer</h2>
|
||||
<p>
|
||||
Here are the top 10 referer.
|
||||
</p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Referer</th>
|
||||
<th>Visitors</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{range $data := .Referer}}
|
||||
<tr>
|
||||
<td>{{if $data.Referer}}{{$data.Referer}}{{else}}(unknown){{end}}</td>
|
||||
<td>{{$data.Visitors}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
<section>
|
||||
<h2>Page Visits</h2>
|
||||
</section>
|
||||
|
||||
@@ -48,6 +48,21 @@ func GetPageVisits(startDate, endDate time.Time) []PageVisits {
|
||||
return pageVisits
|
||||
}
|
||||
|
||||
func GetPages(startDate, endDate time.Time) []pirsch.VisitorPage {
|
||||
pages, err := analyzer.Pages(&pirsch.Filter{From: startDate, To: endDate})
|
||||
|
||||
if err != nil {
|
||||
logbuch.Error("Error reading page statistics", logbuch.Fields{"err": err})
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(pages) > 10 {
|
||||
return pages[:10]
|
||||
}
|
||||
|
||||
return pages
|
||||
}
|
||||
|
||||
func GetLanguages(startDate, endDate time.Time) []pirsch.VisitorLanguage {
|
||||
languages, _, err := analyzer.Languages(&pirsch.Filter{From: startDate, To: endDate})
|
||||
|
||||
@@ -63,6 +78,21 @@ 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})
|
||||
|
||||
if err != nil {
|
||||
logbuch.Error("Error reading referer statistics", logbuch.Fields{"err": err})
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(referer) > 10 {
|
||||
return referer[:10]
|
||||
}
|
||||
|
||||
return referer
|
||||
}
|
||||
|
||||
func GetHourlyVisitors(startDate, endDate time.Time) (template.JS, template.JS) {
|
||||
visitors, err := analyzer.HourlyVisitors(&pirsch.Filter{From: startDate, To: endDate})
|
||||
|
||||
@@ -96,6 +126,17 @@ func GetActiveVisitors() int {
|
||||
return visitors
|
||||
}
|
||||
|
||||
func GetActiveVisitorPages() []pirsch.PageVisitors {
|
||||
pages, err := analyzer.ActiveVisitorsPages(pirsch.NullTenant, time.Second*30)
|
||||
|
||||
if err != nil {
|
||||
logbuch.Error("Error reading active visitor pages", logbuch.Fields{"err": err})
|
||||
return nil
|
||||
}
|
||||
|
||||
return pages
|
||||
}
|
||||
|
||||
func getLabelsAndData(visitors []pirsch.VisitorsPerDay) (template.JS, template.JS) {
|
||||
var labels strings.Builder
|
||||
var dp strings.Builder
|
||||
|
||||
@@ -56,7 +56,6 @@ func NewTracker() (*pirsch.Tracker, context.CancelFunc) {
|
||||
})
|
||||
analyzer = pirsch.NewAnalyzer(store)
|
||||
processor := pirsch.NewProcessor(store, nil)
|
||||
processTrackingData(processor)
|
||||
cancel := pirsch.RunAtMidnight(func() {
|
||||
processTrackingData(processor)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user