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()
|
activeVisitorPages, activeVisitors := tracking.GetActiveVisitors()
|
||||||
totalVisitorsLabels, totalVisitorsDps := tracking.GetTotalVisitors(startDate, endDate)
|
totalVisitorsLabels, totalVisitorsDps, sessionsDps, bouncesDps := tracking.GetTotalVisitors(startDate, endDate)
|
||||||
hourlyVisitorsTodayLabels, hourlyVisitorsTodayDps := tracking.GetHourlyVisitorsToday()
|
hourlyVisitorsTodayLabels, hourlyVisitorsTodayDps := tracking.GetHourlyVisitorsToday()
|
||||||
pageVisitors, pageRank := tracking.GetPageVisits(startDate, endDate)
|
pageVisitors, pageRank := tracking.GetPageVisits(startDate, endDate)
|
||||||
tplCache.RenderWithoutCache(w, "tracking.html", struct {
|
tplCache.RenderWithoutCache(w, "tracking.html", struct {
|
||||||
@@ -132,6 +132,8 @@ func serveTracking() http.HandlerFunc {
|
|||||||
EndDate time.Time
|
EndDate time.Time
|
||||||
TotalVisitorsLabels template.JS
|
TotalVisitorsLabels template.JS
|
||||||
TotalVisitorsDps template.JS
|
TotalVisitorsDps template.JS
|
||||||
|
SessionsDps template.JS
|
||||||
|
BouncesDps template.JS
|
||||||
PageVisitors []tracking.PageVisitors
|
PageVisitors []tracking.PageVisitors
|
||||||
PageRank []tracking.PageVisitors
|
PageRank []tracking.PageVisitors
|
||||||
Languages []pirsch.LanguageStats
|
Languages []pirsch.LanguageStats
|
||||||
@@ -149,6 +151,8 @@ func serveTracking() http.HandlerFunc {
|
|||||||
endDate,
|
endDate,
|
||||||
totalVisitorsLabels,
|
totalVisitorsLabels,
|
||||||
totalVisitorsDps,
|
totalVisitorsDps,
|
||||||
|
sessionsDps,
|
||||||
|
bouncesDps,
|
||||||
pageVisitors,
|
pageVisitors,
|
||||||
pageRank,
|
pageRank,
|
||||||
tracking.GetLanguages(startDate, endDate),
|
tracking.GetLanguages(startDate, endDate),
|
||||||
|
|||||||
@@ -234,12 +234,26 @@
|
|||||||
type: "line",
|
type: "line",
|
||||||
data: {
|
data: {
|
||||||
labels: [{{.TotalVisitorsLabels}}],
|
labels: [{{.TotalVisitorsLabels}}],
|
||||||
datasets: [{
|
datasets: [
|
||||||
backgroundColor: "rgba(127, 127, 127, 0.05)",
|
{
|
||||||
borderColor: "#7f7f7f",
|
backgroundColor: "rgb(43, 180, 0, 0.02)",
|
||||||
|
borderColor: "#289800",
|
||||||
label: "Total Visitors",
|
label: "Total Visitors",
|
||||||
data: [{{.TotalVisitorsDps}}]
|
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",
|
type: "line",
|
||||||
data: {
|
data: {
|
||||||
labels: [{{$data.Labels}}],
|
labels: [{{$data.Labels}}],
|
||||||
datasets: [{
|
datasets: [
|
||||||
backgroundColor: "rgba(127, 127, 127, 0.05)",
|
{
|
||||||
borderColor: "#7f7f7f",
|
backgroundColor: "rgb(43, 180, 0, 0.02)",
|
||||||
|
borderColor: "#289800",
|
||||||
label: "Page Visits",
|
label: "Page Visits",
|
||||||
data: [{{$data.Data}}]
|
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}}
|
{{end}}
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ type PageVisitors struct {
|
|||||||
Visitors int
|
Visitors int
|
||||||
Labels template.JS
|
Labels template.JS
|
||||||
Data template.JS
|
Data template.JS
|
||||||
|
Sessions template.JS
|
||||||
|
Bounces template.JS
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetActiveVisitors() ([]pirsch.Stats, int) {
|
func GetActiveVisitors() ([]pirsch.Stats, int) {
|
||||||
@@ -43,12 +45,12 @@ func GetHourlyVisitorsToday() (template.JS, template.JS) {
|
|||||||
return getLabelsAndDataHourly(visitors)
|
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})
|
visitors, err := analyzer.Visitors(&pirsch.Filter{From: startDate, To: endDate})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logbuch.Error("Error reading visitor statistics", logbuch.Fields{"err": err})
|
logbuch.Error("Error reading visitor statistics", logbuch.Fields{"err": err})
|
||||||
return "", ""
|
return "", "", "", ""
|
||||||
}
|
}
|
||||||
|
|
||||||
return getLabelsAndData(visitors)
|
return getLabelsAndData(visitors)
|
||||||
@@ -65,12 +67,14 @@ func GetPageVisits(startDate, endDate time.Time) ([]PageVisitors, []PageVisitors
|
|||||||
pageVisitors := make([]PageVisitors, len(visits))
|
pageVisitors := make([]PageVisitors, len(visits))
|
||||||
|
|
||||||
for i, visit := range visits {
|
for i, visit := range visits {
|
||||||
labels, data := getLabelsAndData(visit.Stats)
|
labels, data, sessions, bounces := getLabelsAndData(visit.Stats)
|
||||||
pageVisitors[i] = PageVisitors{
|
pageVisitors[i] = PageVisitors{
|
||||||
Path: visit.Path,
|
Path: visit.Path,
|
||||||
Visitors: sumVisitors(visit.Stats),
|
Visitors: sumVisitors(visit.Stats),
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
Data: data,
|
Data: data,
|
||||||
|
Sessions: sessions,
|
||||||
|
Bounces: bounces,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,18 +152,27 @@ func sumVisitors(stats []pirsch.Stats) int {
|
|||||||
return sum
|
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 labels strings.Builder
|
||||||
var dp strings.Builder
|
var dp strings.Builder
|
||||||
|
var sessions strings.Builder
|
||||||
|
var bounces strings.Builder
|
||||||
|
|
||||||
for _, point := range visitors {
|
for _, point := range visitors {
|
||||||
labels.WriteString(fmt.Sprintf("'%s',", point.Day.Format(statisticsDateFormat)))
|
labels.WriteString(fmt.Sprintf("'%s',", point.Day.Format(statisticsDateFormat)))
|
||||||
dp.WriteString(fmt.Sprintf("%d,", point.Visitors))
|
dp.WriteString(fmt.Sprintf("%d,", point.Visitors))
|
||||||
|
sessions.WriteString(fmt.Sprintf("%d,", point.Sessions))
|
||||||
|
bounces.WriteString(fmt.Sprintf("%d,", point.Bounces))
|
||||||
}
|
}
|
||||||
|
|
||||||
labelsStr := labels.String()
|
labelsStr := labels.String()
|
||||||
dataStr := dp.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) {
|
func getLabelsAndDataHourly(visitors []pirsch.VisitorTimeStats) (template.JS, template.JS) {
|
||||||
|
|||||||
Reference in New Issue
Block a user