diff --git a/api/chalicelib/core/product_analytics/events.py b/api/chalicelib/core/product_analytics/events.py index f7b4cea86..99a2914d3 100644 --- a/api/chalicelib/core/product_analytics/events.py +++ b/api/chalicelib/core/product_analytics/events.py @@ -7,14 +7,13 @@ from chalicelib.utils.ch_client import ClickHouseClient from chalicelib.utils.exp_ch_helper import get_sub_condition, get_col_cast logger = logging.getLogger(__name__) -PREDEFINED_EVENTS = { - "CLICK": "String", - "INPUT": "String", - "LOCATION": "String", - "ERROR": "String", - "PERFORMANCE": "String", - "REQUEST": "String" -} +PREDEFINED_EVENTS = [ + "CLICK", + "INPUT", + "LOCATION", + "ERROR", + "REQUEST" +] def get_events(project_id: int, page: schemas.PaginatedSchema): diff --git a/api/chalicelib/core/product_analytics/properties.py b/api/chalicelib/core/product_analytics/properties.py index c88fe1c7d..24fcc7f7e 100644 --- a/api/chalicelib/core/product_analytics/properties.py +++ b/api/chalicelib/core/product_analytics/properties.py @@ -58,6 +58,14 @@ PREDEFINED_PROPERTIES = { "message_id": "UInt64" } +EVENT_DEFAULT_PROPERTIES = { + "CLICK": "label", + "INPUT": "label", + "LOCATION": "url_path", + "ERROR": "name", + "REQUEST": "url_path" +} + def get_all_properties(project_id: int, page: schemas.PaginatedSchema): with ClickHouseClient() as ch_client: @@ -104,7 +112,7 @@ def get_all_properties(project_id: int, page: schemas.PaginatedSchema): return {"total": total, "list": properties} -def get_event_properties(project_id: int, event_name): +def get_event_properties(project_id: int, event_name: str, auto_captured: bool): with ClickHouseClient() as ch_client: r = ch_client.format( """SELECT all_properties.property_name AS name, @@ -115,9 +123,10 @@ def get_event_properties(project_id: int, event_name): WHERE event_properties.project_id = %(project_id)s AND all_properties.project_id = %(project_id)s AND event_properties.event_name = %(event_name)s + AND event_properties.auto_captured = %(auto_captured)s GROUP BY ALL ORDER BY 1;""", - parameters={"project_id": project_id, "event_name": event_name}) + parameters={"project_id": project_id, "event_name": event_name, "auto_captured": auto_captured}) properties = ch_client.execute(r) properties = helper.list_to_camel_case(properties) for i, p in enumerate(properties): @@ -127,6 +136,8 @@ def get_event_properties(project_id: int, event_name): p["dataType"] = exp_ch_helper.simplify_clickhouse_type(PREDEFINED_PROPERTIES[p["name"]]) p["_foundInPredefinedList"] = True p["possibleTypes"] = list(set(exp_ch_helper.simplify_clickhouse_types(p["possibleTypes"]))) + p["defaultProperty"] = auto_captured and event_name in EVENT_DEFAULT_PROPERTIES \ + and p["name"] == EVENT_DEFAULT_PROPERTIES[event_name] return properties diff --git a/api/routers/subs/product_analytics.py b/api/routers/subs/product_analytics.py index 950c615fb..3b289cd25 100644 --- a/api/routers/subs/product_analytics.py +++ b/api/routers/subs/product_analytics.py @@ -34,11 +34,12 @@ def get_all_events(projectId: int, filter_query: Annotated[schemas.PaginatedSche @app.get('/{projectId}/properties/search', tags=["product_analytics"]) -def get_event_properties(projectId: int, event_name: str = None, +def get_event_properties(projectId: int, en: str = Query(default=None, description="event name"), + ac: bool = Query(description="auto captured"), context: schemas.CurrentContext = Depends(OR_context)): - if not event_name or len(event_name) == 0: + if not en or len(en) == 0: return {"data": []} - return {"data": properties.get_event_properties(project_id=projectId, event_name=event_name)} + return {"data": properties.get_event_properties(project_id=projectId, event_name=en, auto_captured=ac)} @app.post('/{projectId}/events/search', tags=["product_analytics"])