mirror of
https://github.com/Kugelschieber/marvinblum.git
synced 2026-01-18 06:40:27 +00:00
Added sessions and bounces to tracking page.
This commit is contained in:
6
main.go
6
main.go
@@ -123,7 +123,7 @@ func serveTracking() http.HandlerFunc {
|
||||
}
|
||||
|
||||
activeVisitorPages, activeVisitors := tracking.GetActiveVisitors()
|
||||
totalVisitorsLabels, totalVisitorsDps := tracking.GetTotalVisitors(startDate, endDate)
|
||||
totalVisitorsLabels, totalVisitorsDps, sessionsDps, bouncesDps := tracking.GetTotalVisitors(startDate, endDate)
|
||||
hourlyVisitorsTodayLabels, hourlyVisitorsTodayDps := tracking.GetHourlyVisitorsToday()
|
||||
pageVisitors, pageRank := tracking.GetPageVisits(startDate, endDate)
|
||||
tplCache.RenderWithoutCache(w, "tracking.html", struct {
|
||||
@@ -132,6 +132,8 @@ func serveTracking() http.HandlerFunc {
|
||||
EndDate time.Time
|
||||
TotalVisitorsLabels template.JS
|
||||
TotalVisitorsDps template.JS
|
||||
SessionsDps template.JS
|
||||
BouncesDps template.JS
|
||||
PageVisitors []tracking.PageVisitors
|
||||
PageRank []tracking.PageVisitors
|
||||
Languages []pirsch.LanguageStats
|
||||
@@ -149,6 +151,8 @@ func serveTracking() http.HandlerFunc {
|
||||
endDate,
|
||||
totalVisitorsLabels,
|
||||
totalVisitorsDps,
|
||||
sessionsDps,
|
||||
bouncesDps,
|
||||
pageVisitors,
|
||||
pageRank,
|
||||
tracking.GetLanguages(startDate, endDate),
|
||||
|
||||
@@ -234,12 +234,26 @@
|
||||
type: "line",
|
||||
data: {
|
||||
labels: [{{.TotalVisitorsLabels}}],
|
||||
datasets: [{
|
||||
backgroundColor: "rgba(127, 127, 127, 0.05)",
|
||||
borderColor: "#7f7f7f",
|
||||
label: "Total Visitors",
|
||||
data: [{{.TotalVisitorsDps}}]
|
||||
}]
|
||||
datasets: [
|
||||
{
|
||||
backgroundColor: "rgb(43, 180, 0, 0.02)",
|
||||
borderColor: "#289800",
|
||||
label: "Total Visitors",
|
||||
data: [{{.TotalVisitorsDps}}]
|
||||
},
|
||||
{
|
||||
backgroundColor: "rgb(0, 63, 197, 0.02)",
|
||||
borderColor: "#00359f",
|
||||
label: "Sessions",
|
||||
data: [{{.SessionsDps}}]
|
||||
},
|
||||
{
|
||||
backgroundColor: "rgba(194, 0, 0, 0.02)",
|
||||
borderColor: "#980000",
|
||||
label: "Bounces",
|
||||
data: [{{.BouncesDps}}]
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
@@ -263,12 +277,26 @@
|
||||
type: "line",
|
||||
data: {
|
||||
labels: [{{$data.Labels}}],
|
||||
datasets: [{
|
||||
backgroundColor: "rgba(127, 127, 127, 0.05)",
|
||||
borderColor: "#7f7f7f",
|
||||
label: "Page Visits",
|
||||
data: [{{$data.Data}}]
|
||||
}]
|
||||
datasets: [
|
||||
{
|
||||
backgroundColor: "rgb(43, 180, 0, 0.02)",
|
||||
borderColor: "#289800",
|
||||
label: "Page Visits",
|
||||
data: [{{$data.Data}}]
|
||||
},
|
||||
{
|
||||
backgroundColor: "rgb(0, 63, 197, 0.02)",
|
||||
borderColor: "#00359f",
|
||||
label: "Sessions",
|
||||
data: [{{$data.Sessions}}]
|
||||
},
|
||||
{
|
||||
backgroundColor: "rgba(194, 0, 0, 0.02)",
|
||||
borderColor: "#980000",
|
||||
label: "Bounces",
|
||||
data: [{{$data.Bounces}}]
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
{{end}}
|
||||
|
||||
@@ -19,6 +19,8 @@ type PageVisitors struct {
|
||||
Visitors int
|
||||
Labels template.JS
|
||||
Data template.JS
|
||||
Sessions template.JS
|
||||
Bounces template.JS
|
||||
}
|
||||
|
||||
func GetActiveVisitors() ([]pirsch.Stats, int) {
|
||||
@@ -43,12 +45,12 @@ func GetHourlyVisitorsToday() (template.JS, template.JS) {
|
||||
return getLabelsAndDataHourly(visitors)
|
||||
}
|
||||
|
||||
func GetTotalVisitors(startDate, endDate time.Time) (template.JS, template.JS) {
|
||||
func GetTotalVisitors(startDate, endDate time.Time) (template.JS, template.JS, template.JS, template.JS) {
|
||||
visitors, err := analyzer.Visitors(&pirsch.Filter{From: startDate, To: endDate})
|
||||
|
||||
if err != nil {
|
||||
logbuch.Error("Error reading visitor statistics", logbuch.Fields{"err": err})
|
||||
return "", ""
|
||||
return "", "", "", ""
|
||||
}
|
||||
|
||||
return getLabelsAndData(visitors)
|
||||
@@ -65,12 +67,14 @@ func GetPageVisits(startDate, endDate time.Time) ([]PageVisitors, []PageVisitors
|
||||
pageVisitors := make([]PageVisitors, len(visits))
|
||||
|
||||
for i, visit := range visits {
|
||||
labels, data := getLabelsAndData(visit.Stats)
|
||||
labels, data, sessions, bounces := getLabelsAndData(visit.Stats)
|
||||
pageVisitors[i] = PageVisitors{
|
||||
Path: visit.Path,
|
||||
Visitors: sumVisitors(visit.Stats),
|
||||
Labels: labels,
|
||||
Data: data,
|
||||
Sessions: sessions,
|
||||
Bounces: bounces,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,18 +152,27 @@ func sumVisitors(stats []pirsch.Stats) int {
|
||||
return sum
|
||||
}
|
||||
|
||||
func getLabelsAndData(visitors []pirsch.Stats) (template.JS, template.JS) {
|
||||
func getLabelsAndData(visitors []pirsch.Stats) (template.JS, template.JS, template.JS, template.JS) {
|
||||
var labels strings.Builder
|
||||
var dp strings.Builder
|
||||
var sessions strings.Builder
|
||||
var bounces strings.Builder
|
||||
|
||||
for _, point := range visitors {
|
||||
labels.WriteString(fmt.Sprintf("'%s',", point.Day.Format(statisticsDateFormat)))
|
||||
dp.WriteString(fmt.Sprintf("%d,", point.Visitors))
|
||||
sessions.WriteString(fmt.Sprintf("%d,", point.Sessions))
|
||||
bounces.WriteString(fmt.Sprintf("%d,", point.Bounces))
|
||||
}
|
||||
|
||||
labelsStr := labels.String()
|
||||
dataStr := dp.String()
|
||||
return template.JS(labelsStr[:len(labelsStr)-1]), template.JS(dataStr[:len(dataStr)-1])
|
||||
sessionsStr := sessions.String()
|
||||
bouncesStr := sessions.String()
|
||||
return template.JS(labelsStr[:len(labelsStr)-1]),
|
||||
template.JS(dataStr[:len(dataStr)-1]),
|
||||
template.JS(sessionsStr[:len(sessionsStr)-1]),
|
||||
template.JS(bouncesStr[:len(sessionsStr)-1])
|
||||
}
|
||||
|
||||
func getLabelsAndDataHourly(visitors []pirsch.VisitorTimeStats) (template.JS, template.JS) {
|
||||
|
||||
Reference in New Issue
Block a user