mirror of
https://github.com/status-im/fathom.git
synced 2025-03-01 11:30:28 +00:00
76 lines
2.4 KiB
Go
76 lines
2.4 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
)
|
|
|
|
// URL: /api/stats/site
|
|
func (api *API) GetSiteStatsHandler(w http.ResponseWriter, r *http.Request) error {
|
|
params := GetRequestParams(r)
|
|
result, err := api.database.GetAggregatedSiteStats(params.SiteID, params.StartDate, params.EndDate)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return respond(w, http.StatusOK, envelope{Data: result})
|
|
}
|
|
|
|
// URL: /api/stats/site/pageviews
|
|
func (api *API) GetSiteStatsPageviewsHandler(w http.ResponseWriter, r *http.Request) error {
|
|
params := GetRequestParams(r)
|
|
result, err := api.database.GetTotalSiteViews(params.SiteID, params.StartDate, params.EndDate)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return respond(w, http.StatusOK, envelope{Data: result})
|
|
}
|
|
|
|
// URL: /api/stats/site/visitors
|
|
func (api *API) GetSiteStatsVisitorsHandler(w http.ResponseWriter, r *http.Request) error {
|
|
params := GetRequestParams(r)
|
|
result, err := api.database.GetTotalSiteVisitors(params.SiteID, params.StartDate, params.EndDate)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return respond(w, http.StatusOK, envelope{Data: result})
|
|
}
|
|
|
|
// URL: /api/stats/site/duration
|
|
func (api *API) GetSiteStatsDurationHandler(w http.ResponseWriter, r *http.Request) error {
|
|
params := GetRequestParams(r)
|
|
result, err := api.database.GetAverageSiteDuration(params.SiteID, params.StartDate, params.EndDate)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return respond(w, http.StatusOK, envelope{Data: result})
|
|
}
|
|
|
|
// URL: /api/stats/site/bounces
|
|
func (api *API) GetSiteStatsBouncesHandler(w http.ResponseWriter, r *http.Request) error {
|
|
params := GetRequestParams(r)
|
|
result, err := api.database.GetAverageSiteBounceRate(params.SiteID, params.StartDate, params.EndDate)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return respond(w, http.StatusOK, envelope{Data: result})
|
|
}
|
|
|
|
// URL: /api/stats/site/realtime
|
|
func (api *API) GetSiteStatsRealtimeHandler(w http.ResponseWriter, r *http.Request) error {
|
|
params := GetRequestParams(r)
|
|
result, err := api.database.GetRealtimeVisitorCount(params.SiteID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return respond(w, http.StatusOK, envelope{Data: result})
|
|
}
|
|
|
|
// URL: /api/stats/site/groupby/day
|
|
func (api *API) GetSiteStatsPerDayHandler(w http.ResponseWriter, r *http.Request) error {
|
|
params := GetRequestParams(r)
|
|
result, err := api.database.GetSiteStatsPerDay(params.SiteID, params.StartDate, params.EndDate)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return respond(w, http.StatusOK, envelope{Data: result})
|
|
}
|