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/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/emvi/api-go v0.2.2
|
github.com/emvi/api-go v0.2.2
|
||||||
github.com/emvi/logbuch v1.1.1
|
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/go-sql-driver/mysql v1.5.0 // indirect
|
||||||
github.com/gorilla/mux v1.7.4
|
github.com/gorilla/mux v1.7.4
|
||||||
github.com/gosimple/slug v1.9.0
|
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.2.0/go.mod h1:GDijqLHM331iWtmDmc7th19RxDrZadRkKoNvd9/kDX8=
|
||||||
github.com/emvi/pirsch v1.3.0 h1:csgIvQKMMWF9EG4Dkfd4dFux6kfzOFC8PuNPWvsj7zM=
|
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.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.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 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
|
||||||
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
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
|
TotalVisitorsLabels template.JS
|
||||||
TotalVisitorsDps template.JS
|
TotalVisitorsDps template.JS
|
||||||
PageVisits []tracking.PageVisits
|
PageVisits []tracking.PageVisits
|
||||||
|
Pages []pirsch.VisitorPage
|
||||||
Languages []pirsch.VisitorLanguage
|
Languages []pirsch.VisitorLanguage
|
||||||
|
Referer []pirsch.VisitorReferer
|
||||||
HourlyVisitorsLabels template.JS
|
HourlyVisitorsLabels template.JS
|
||||||
HourlyVisitorsDps template.JS
|
HourlyVisitorsDps template.JS
|
||||||
HourlyVisitorsTodayLabels template.JS
|
HourlyVisitorsTodayLabels template.JS
|
||||||
HourlyVisitorsTodayDps template.JS
|
HourlyVisitorsTodayDps template.JS
|
||||||
ActiveVisitors int
|
ActiveVisitors int
|
||||||
|
ActiveVisitorPages []pirsch.PageVisitors
|
||||||
}{
|
}{
|
||||||
start,
|
start,
|
||||||
startDate,
|
startDate,
|
||||||
@@ -167,12 +170,15 @@ func serveTracking() http.HandlerFunc {
|
|||||||
totalVisitorsLabels,
|
totalVisitorsLabels,
|
||||||
totalVisitorsDps,
|
totalVisitorsDps,
|
||||||
tracking.GetPageVisits(startDate, endDate),
|
tracking.GetPageVisits(startDate, endDate),
|
||||||
|
tracking.GetPages(startDate, endDate),
|
||||||
tracking.GetLanguages(startDate, endDate),
|
tracking.GetLanguages(startDate, endDate),
|
||||||
|
tracking.GetReferer(startDate, endDate),
|
||||||
hourlyVisitorsLabels,
|
hourlyVisitorsLabels,
|
||||||
hourlyVisitorsDps,
|
hourlyVisitorsDps,
|
||||||
hourlyVisitorsTodayLabels,
|
hourlyVisitorsTodayLabels,
|
||||||
hourlyVisitorsTodayDps,
|
hourlyVisitorsTodayDps,
|
||||||
tracking.GetActiveVisitors(),
|
tracking.GetActiveVisitors(),
|
||||||
|
tracking.GetActiveVisitorPages(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,25 @@
|
|||||||
The next diagram shows active visitors for each hour of today.
|
The next diagram shows active visitors for each hour of today.
|
||||||
</p>
|
</p>
|
||||||
<canvas id="hourlyVisitorsToday" class="tracking"></canvas>
|
<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>
|
||||||
<section>
|
<section>
|
||||||
<h2>Total Visitors</h2>
|
<h2>Total Visitors</h2>
|
||||||
@@ -40,6 +59,28 @@
|
|||||||
</p>
|
</p>
|
||||||
<canvas id="hourlyVisitors" class="tracking"></canvas>
|
<canvas id="hourlyVisitors" class="tracking"></canvas>
|
||||||
</section>
|
</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>
|
<section>
|
||||||
<h2>Languages</h2>
|
<h2>Languages</h2>
|
||||||
<p>
|
<p>
|
||||||
@@ -47,20 +88,42 @@
|
|||||||
</p>
|
</p>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Language</th>
|
<th>Language</th>
|
||||||
<th>Absolute</th>
|
<th>Absolute</th>
|
||||||
<th>Relative</th>
|
<th>Relative</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{{range $data := .Languages}}
|
{{range $data := .Languages}}
|
||||||
|
<tr>
|
||||||
|
<td>{{if $data.Language}}{{$data.Language}}{{else}}(not set){{end}}</td>
|
||||||
|
<td>{{$data.Visitors}}</td>
|
||||||
|
<td>{{round (multiply $data.RelativeVisitors 100)}} %</td>
|
||||||
|
</tr>
|
||||||
|
{{end}}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<h2>Referer</h2>
|
||||||
|
<p>
|
||||||
|
Here are the top 10 referer.
|
||||||
|
</p>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{if $data.Language}}{{$data.Language}}{{else}}(not set){{end}}</td>
|
<th>Referer</th>
|
||||||
<td>{{$data.Visitors}}</td>
|
<th>Visitors</th>
|
||||||
<td>{{round (multiply $data.RelativeVisitors 100)}} %</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
{{end}}
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{{range $data := .Referer}}
|
||||||
|
<tr>
|
||||||
|
<td>{{if $data.Referer}}{{$data.Referer}}{{else}}(unknown){{end}}</td>
|
||||||
|
<td>{{$data.Visitors}}</td>
|
||||||
|
</tr>
|
||||||
|
{{end}}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -48,6 +48,21 @@ func GetPageVisits(startDate, endDate time.Time) []PageVisits {
|
|||||||
return 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 {
|
func GetLanguages(startDate, endDate time.Time) []pirsch.VisitorLanguage {
|
||||||
languages, _, err := analyzer.Languages(&pirsch.Filter{From: startDate, To: endDate})
|
languages, _, err := analyzer.Languages(&pirsch.Filter{From: startDate, To: endDate})
|
||||||
|
|
||||||
@@ -63,6 +78,21 @@ func GetLanguages(startDate, endDate time.Time) []pirsch.VisitorLanguage {
|
|||||||
return languages
|
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) {
|
func GetHourlyVisitors(startDate, endDate time.Time) (template.JS, template.JS) {
|
||||||
visitors, err := analyzer.HourlyVisitors(&pirsch.Filter{From: startDate, To: endDate})
|
visitors, err := analyzer.HourlyVisitors(&pirsch.Filter{From: startDate, To: endDate})
|
||||||
|
|
||||||
@@ -96,6 +126,17 @@ func GetActiveVisitors() int {
|
|||||||
return visitors
|
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) {
|
func getLabelsAndData(visitors []pirsch.VisitorsPerDay) (template.JS, template.JS) {
|
||||||
var labels strings.Builder
|
var labels strings.Builder
|
||||||
var dp strings.Builder
|
var dp strings.Builder
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ func NewTracker() (*pirsch.Tracker, context.CancelFunc) {
|
|||||||
})
|
})
|
||||||
analyzer = pirsch.NewAnalyzer(store)
|
analyzer = pirsch.NewAnalyzer(store)
|
||||||
processor := pirsch.NewProcessor(store, nil)
|
processor := pirsch.NewProcessor(store, nil)
|
||||||
processTrackingData(processor)
|
|
||||||
cancel := pirsch.RunAtMidnight(func() {
|
cancel := pirsch.RunAtMidnight(func() {
|
||||||
processTrackingData(processor)
|
processTrackingData(processor)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user