diff --git a/api/chalicelib/core/custom_metrics.py b/api/chalicelib/core/custom_metrics.py index e26e48020..7c2325e46 100644 --- a/api/chalicelib/core/custom_metrics.py +++ b/api/chalicelib/core/custom_metrics.py @@ -137,6 +137,10 @@ def __get_table_of_urls(project_id: int, data: schemas.CardTable, user_id: int = return __get_table_of_series(project_id=project_id, data=data) +def __get_table_of_referrers(project_id: int, data: schemas.CardTable, user_id: int = None): + return __get_table_of_series(project_id=project_id, data=data) + + def __get_table_chart(project_id: int, data: schemas.CardTable, user_id: int): supported = { schemas.MetricOfTable.SESSIONS: __get_table_of_sessions, @@ -147,6 +151,7 @@ def __get_table_chart(project_id: int, data: schemas.CardTable, user_id: int): schemas.MetricOfTable.USER_DEVICE: __get_table_of_devises, schemas.MetricOfTable.USER_COUNTRY: __get_table_of_countries, schemas.MetricOfTable.VISITED_URL: __get_table_of_urls, + schemas.MetricOfTable.REFERRER: __get_table_of_referrers, } return supported.get(data.metric_of, not_supported)(project_id=project_id, data=data, user_id=user_id) diff --git a/api/chalicelib/core/sessions.py b/api/chalicelib/core/sessions.py index 9d88e1265..f7cf63f1f 100644 --- a/api/chalicelib/core/sessions.py +++ b/api/chalicelib/core/sessions.py @@ -357,9 +357,13 @@ def search2_table(data: schemas.SessionsSearchPayloadSchema, project_id: int, de main_col = "path" extra_col = ", path" distinct_on += ",path" + elif metric_of == schemas.MetricOfTable.REFERRER: + main_col = "referrer" + extra_col = ", referrer" + if metric_format == schemas.MetricExtendedFormatType.SESSION_COUNT: main_query = f"""SELECT COUNT(*) AS count, - COALESCE(SUM(users_sessions.session_count),0) AS count, + COALESCE(SUM(users_sessions.total),0) AS total, COALESCE(JSONB_AGG(users_sessions) FILTER ( WHERE rn > %(limit_s)s AND rn <= %(limit_e)s ), '[]'::JSONB) AS values @@ -376,7 +380,7 @@ def search2_table(data: schemas.SessionsSearchPayloadSchema, project_id: int, de ) AS full_sessions {extra_where} GROUP BY {main_col} - ORDER BY session_count DESC) AS users_sessions;""" + ORDER BY total DESC) AS users_sessions;""" else: main_query = f"""SELECT COUNT(*) AS count, COALESCE(SUM(users_sessions.user_count),0) AS count, diff --git a/api/schemas/schemas.py b/api/schemas/schemas.py index 145b8cd9d..8154ede06 100644 --- a/api/schemas/schemas.py +++ b/api/schemas/schemas.py @@ -1008,6 +1008,7 @@ class MetricOfTable(str, Enum): VISITED_URL = "location" SESSIONS = "sessions" ERRORS = "jsException" + REFERRER = "referrer" class MetricOfTimeseries(str, Enum):