diff --git a/analyticsApi/main.go b/analyticsApi/main.go index fb01887..ea960a5 100644 --- a/analyticsApi/main.go +++ b/analyticsApi/main.go @@ -223,27 +223,27 @@ func initPageViewCount(app *pocketbase.PocketBase, e *core.ServeEvent) { // // { // "device_type": [ -// { "value": "", "count": , "error_count": }, +// { "value": "", "count": , "error_count": , "success_count": }, // ... // ], // "browser_name": [ -// { "value": "", "count": , "error_count": }, +// { "value": "", "count": , "error_count": , "success_count": }, // ... // ], // "operating_system": [ -// { "value": "", "count": , "error_count": }, +// { "value": "", "count": , "error_count": , "success_count": }, // ... // ], // "user_agent": [ -// { "value": "", "count": , "error_count": }, +// { "value": "", "count": , "error_count": , "success_count": }, // ... // ], // "geo_country_code": [ -// { "value": "", "count": , "error_count": }, +// { "value": "", "count": , "error_count": , "success_count": }, // ... // ], // "preferred_language": [ -// { "value": "", "count": , "error_count": }, +// { "value": "", "count": , "error_count": , "success_count": }, // ... // ] // } @@ -266,9 +266,10 @@ func initAggregateCount(app *pocketbase.PocketBase, e *core.ServeEvent) { } type Data struct { - Value string `db:"value" json:"value"` - Count int `db:"count" json:"count"` - ErrorCount int `db:"error_count" json:"error_count"` + Value string `db:"value" json:"value"` + Count int `db:"count" json:"count"` + SuccessCount int `db:"success_count" json:"success_count"` + ErrorCount int `db:"error_count" json:"error_count"` } // Use a map to store the response data @@ -284,6 +285,7 @@ func initAggregateCount(app *pocketbase.PocketBase, e *core.ServeEvent) { SELECT IFNULL(` + field + `, 'N/A') as value, COUNT(id) AS count, + SUM(CASE WHEN error IS NULL THEN 1 ELSE 0 END) AS success_count, SUM(CASE WHEN error IS NOT NULL THEN 1 ELSE 0 END) AS error_count FROM analyticsPageViewsWithSessionDetail WHERE created >= {:startDate}