feat(analyticsApi): added error_count to initAggregateCount
Build and Push Docker image / build-and-push (push) Successful in 2m13s
Details
Build and Push Docker image / build-and-push (push) Successful in 2m13s
Details
This commit is contained in:
parent
c9356a419e
commit
099026cd9f
|
@ -223,33 +223,34 @@ func initPageViewCount(app *pocketbase.PocketBase, e *core.ServeEvent) {
|
||||||
//
|
//
|
||||||
// {
|
// {
|
||||||
// "device_type": [
|
// "device_type": [
|
||||||
// { "value": "<device type>", "count": <session count> },
|
// { "value": "<device type>", "count": <session count>, "error_count": <error count> },
|
||||||
// ...
|
// ...
|
||||||
// ],
|
// ],
|
||||||
// "browser_name": [
|
// "browser_name": [
|
||||||
// { "value": "<browser name>", "count": <session count> },
|
// { "value": "<browser name>", "count": <session count>, "error_count": <error count> },
|
||||||
// ...
|
// ...
|
||||||
// ],
|
// ],
|
||||||
// "operating_system": [
|
// "operating_system": [
|
||||||
// { "value": "<operating system>", "count": <session count> },
|
// { "value": "<operating system>", "count": <session count>, "error_count": <error count> },
|
||||||
// ...
|
// ...
|
||||||
// ],
|
// ],
|
||||||
// "user_agent": [
|
// "user_agent": [
|
||||||
// { "value": "<user agent>", "count": <session count> },
|
// { "value": "<user agent>", "count": <session count>, "error_count": <error count> },
|
||||||
// ...
|
// ...
|
||||||
// ],
|
// ],
|
||||||
// "geo_country_code": [
|
// "geo_country_code": [
|
||||||
// { "value": "<country code>", "count": <session count> },
|
// { "value": "<country code>", "count": <session count>, "error_count": <error count> },
|
||||||
// ...
|
// ...
|
||||||
// ],
|
// ],
|
||||||
// "preferred_language": [
|
// "preferred_language": [
|
||||||
// { "value": "<preferred language>", "count": <session count> },
|
// { "value": "<preferred language>", "count": <session count>, "error_count": <error count> },
|
||||||
// ...
|
// ...
|
||||||
// ]
|
// ]
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// Each category includes an array of objects where `value` is the specific item (e.g., a device type or browser name)
|
// Each category includes an array of objects where `value` is the specific item (e.g., a device type or browser name),
|
||||||
// and `count` is the number of sessions matching that item since `startDate`.
|
// `count` is the total number of sessions matching that item since `startDate`, and `error_count` is the number
|
||||||
|
// of sessions with errors for that item (where the `error` field is not NULL) since `startDate`.
|
||||||
func initAggregateCount(app *pocketbase.PocketBase, e *core.ServeEvent) {
|
func initAggregateCount(app *pocketbase.PocketBase, e *core.ServeEvent) {
|
||||||
e.Router.GET("/api/analytics/aggregateCount", func(c echo.Context) error {
|
e.Router.GET("/api/analytics/aggregateCount", func(c echo.Context) error {
|
||||||
|
|
||||||
|
@ -265,8 +266,9 @@ func initAggregateCount(app *pocketbase.PocketBase, e *core.ServeEvent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Data struct {
|
type Data struct {
|
||||||
Value string `db:"value" json:"value"`
|
Value string `db:"value" json:"value"`
|
||||||
Count int `db:"count" json:"count"`
|
Count int `db:"count" json:"count"`
|
||||||
|
ErrorCount int `db:"error_count" json:"error_count"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use a map to store the response data
|
// Use a map to store the response data
|
||||||
|
@ -279,7 +281,10 @@ func initAggregateCount(app *pocketbase.PocketBase, e *core.ServeEvent) {
|
||||||
|
|
||||||
err := app.Dao().DB().
|
err := app.Dao().DB().
|
||||||
NewQuery(`
|
NewQuery(`
|
||||||
SELECT IFNULL(` + field + `, 'N/A') as value, COUNT(id) AS count
|
SELECT
|
||||||
|
IFNULL(` + field + `, 'N/A') as value,
|
||||||
|
COUNT(id) AS count,
|
||||||
|
SUM(CASE WHEN error IS NOT NULL THEN 1 ELSE 0 END) AS error_count
|
||||||
FROM analyticsSessions
|
FROM analyticsSessions
|
||||||
WHERE created >= {:startDate}
|
WHERE created >= {:startDate}
|
||||||
GROUP BY ` + field).
|
GROUP BY ` + field).
|
||||||
|
@ -299,7 +304,6 @@ func initAggregateCount(app *pocketbase.PocketBase, e *core.ServeEvent) {
|
||||||
// Return the final JSON response
|
// Return the final JSON response
|
||||||
return c.JSON(200, response)
|
return c.JSON(200, response)
|
||||||
}, apis.ActivityLogger(app))
|
}, apis.ActivityLogger(app))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitAnalyticsApi initializes analytics api endpoints
|
// InitAnalyticsApi initializes analytics api endpoints
|
||||||
|
|
Loading…
Reference in New Issue