diff --git a/main.go b/main.go index bcd4802..0f210be 100644 --- a/main.go +++ b/main.go @@ -142,6 +142,7 @@ func serveTracking() http.HandlerFunc { OS []pirsch.OSStats Countries []pirsch.CountryStats Platform *pirsch.VisitorStats + TimeOfDay []pirsch.TimeOfDayVisitors HourlyVisitorsTodayLabels template.JS HourlyVisitorsTodayDps template.JS ActiveVisitors int @@ -162,6 +163,7 @@ func serveTracking() http.HandlerFunc { tracking.GetOS(startDate, endDate), tracking.GetCountry(startDate, endDate), tracking.GetPlatform(startDate, endDate), + tracking.GetVisitorTimeOfDay(startDate, endDate), hourlyVisitorsTodayLabels, hourlyVisitorsTodayDps, activeVisitors, diff --git a/template/tracking.html b/template/tracking.html index 33ba764..f6a288e 100644 --- a/template/tracking.html +++ b/template/tracking.html @@ -134,20 +134,20 @@

Browser

- - - - - + + + + + - {{range $data := .Browser}} - - - - - - {{end}} + {{range $data := .Browser}} + + + + + + {{end}}
BrowserAbsoluteRelative
BrowserAbsoluteRelative
{{if $data.Browser.String}}{{$data.Browser.String}}{{else}}(unknown){{end}}{{$data.Visitors}}{{round (multiply $data.RelativeVisitors 100)}} %
{{if $data.Browser.String}}{{$data.Browser.String}}{{else}}(unknown){{end}}{{$data.Visitors}}{{round (multiply $data.RelativeVisitors 100)}} %
@@ -155,20 +155,20 @@

Operating System

- - - - - + + + + + - {{range $data := .OS}} - - - - - - {{end}} + {{range $data := .OS}} + + + + + + {{end}}
OSAbsoluteRelative
OSAbsoluteRelative
{{if $data.OS.String}}{{$data.OS.String}}{{else}}(unknown){{end}}{{$data.Visitors}}{{round (multiply $data.RelativeVisitors 100)}} %
{{if $data.OS.String}}{{$data.OS.String}}{{else}}(unknown){{end}}{{$data.Visitors}}{{round (multiply $data.RelativeVisitors 100)}} %
@@ -176,20 +176,20 @@

Countries

- - - - - + + + + + - {{range $data := .Countries}} - - - - - - {{end}} + {{range $data := .Countries}} + + + + + + {{end}}
CountryAbsoluteRelative
CountryAbsoluteRelative
{{if $data.CountryCode.String}}{{$data.CountryCode.String}}{{else}}(unknown){{end}}{{$data.Visitors}}{{round (multiply $data.RelativeVisitors 100)}} %
{{if $data.CountryCode.String}}{{$data.CountryCode.String}}{{else}}(unknown){{end}}{{$data.Visitors}}{{round (multiply $data.RelativeVisitors 100)}} %
@@ -200,11 +200,11 @@
- - - - - + + + + + @@ -225,6 +225,30 @@
PlatformAbsoluteRelative
PlatformAbsoluteRelative
+
+

Time of Day

+ + + + + {{range $day := .TimeOfDay}} + + {{end}} + + + + {{$global := .}} + {{range $i := (intRange 0 24)}} + + + {{range $j, $day := $global.TimeOfDay}} + + {{end}} + + {{end}} + +
Time{{format $day.Day "Mon 01/02"}}
{{$i}}{{(index (index $global.TimeOfDay $j).Stats $i).Visitors}}
+

Page Visits

diff --git a/tpl/template.go b/tpl/template.go index 2f19393..60cd339 100644 --- a/tpl/template.go +++ b/tpl/template.go @@ -40,6 +40,7 @@ func (cache *Cache) load() { "format": func(t time.Time, layout string) string { return t.Format(layout) }, "multiply": func(f, x float64) float64 { return f * x }, "round": func(f float64) string { return fmt.Sprintf("%.2f", f) }, + "intRange": intRange, } var err error cache.tpl, err = template.New("").Funcs(funcMap).ParseGlob(templateDir) @@ -100,3 +101,17 @@ func (cache *Cache) Clear() { defer cache.m.Unlock() cache.cache = make(map[string][]byte) } + +func intRange(start, end int) []int { + if end-start < 0 { + return []int{} + } + + r := make([]int, end-start) + + for i := 0; i < end-start; i++ { + r[i] = start + i + } + + return r +} diff --git a/tracking/statistics.go b/tracking/statistics.go index 7554891..84107df 100644 --- a/tracking/statistics.go +++ b/tracking/statistics.go @@ -157,6 +157,17 @@ func GetPlatform(startDate, endDate time.Time) *pirsch.VisitorStats { return analyzer.Platform(&pirsch.Filter{From: startDate, To: endDate}) } +func GetVisitorTimeOfDay(startDate, endDate time.Time) []pirsch.TimeOfDayVisitors { + visitors, err := analyzer.TimeOfDay(&pirsch.Filter{From: startDate, To: endDate}) + + if err != nil { + logbuch.Error("Error reading visitor time of day statistics", logbuch.Fields{"err": err}) + return nil + } + + return visitors +} + func sumVisitors(stats []pirsch.Stats) int { sum := 0