Dev (#2318)
* refactor(chalice): upgraded dependencies * refactor(chalice): upgraded dependencies feat(chalice): support heatmaps * feat(chalice): support table-of-browsers showing user-count * feat(chalice): support table-of-devices showing user-count * feat(chalice): support table-of-URLs showing user-count * feat(chalice): clickmaps&heatmaps
This commit is contained in:
parent
5fc087abd9
commit
fa51d8caa1
4 changed files with 81 additions and 6 deletions
|
|
@ -80,7 +80,7 @@ def get_by_url(project_id, data: schemas.GetHeatmapPayloadSchema):
|
|||
return helper.list_to_camel_case(rows)
|
||||
|
||||
|
||||
def get_by_url_and_session_id(project_id, session_id, data: schemas.GetHeatmapBasePayloadSchema):
|
||||
def get_x_y_by_url_and_session_id(project_id, session_id, data: schemas.GetHeatmapBasePayloadSchema):
|
||||
args = {"session_id": session_id, "url": data.url}
|
||||
constraints = ["session_id = %(session_id)s",
|
||||
"(url = %(url)s OR path= %(url)s)",
|
||||
|
|
@ -108,6 +108,35 @@ def get_by_url_and_session_id(project_id, session_id, data: schemas.GetHeatmapBa
|
|||
return helper.list_to_camel_case(rows)
|
||||
|
||||
|
||||
def get_selectors_by_url_and_session_id(project_id, session_id, data: schemas.GetHeatmapBasePayloadSchema):
|
||||
args = {"session_id": session_id, "url": data.url}
|
||||
constraints = ["session_id = %(session_id)s",
|
||||
"(url = %(url)s OR path= %(url)s)"]
|
||||
query_from = "events.clicks"
|
||||
|
||||
with pg_client.PostgresClient() as cur:
|
||||
query = cur.mogrify(f"""SELECT selector, COUNT(1) AS count
|
||||
FROM {query_from}
|
||||
WHERE {" AND ".join(constraints)}
|
||||
GROUP BY 1
|
||||
ORDER BY count DESC;""", args)
|
||||
logger.debug("---------")
|
||||
logger.debug(query.decode('UTF-8'))
|
||||
logger.debug("---------")
|
||||
try:
|
||||
cur.execute(query)
|
||||
except Exception as err:
|
||||
logger.warning("--------- HEATMAP-selector-session_id SEARCH QUERY EXCEPTION -----------")
|
||||
logger.warning(query.decode('UTF-8'))
|
||||
logger.warning("--------- PAYLOAD -----------")
|
||||
logger.warning(data)
|
||||
logger.warning("--------------------")
|
||||
raise err
|
||||
rows = cur.fetchall()
|
||||
|
||||
return helper.list_to_camel_case(rows)
|
||||
|
||||
|
||||
SESSION_PROJECTION_COLS = """s.project_id,
|
||||
s.session_id::text AS session_id,
|
||||
s.user_uuid,
|
||||
|
|
|
|||
|
|
@ -417,11 +417,18 @@ def get_heatmaps_by_url(projectId: int, data: schemas.GetHeatmapPayloadSchema =
|
|||
return {"data": heatmaps.get_by_url(project_id=projectId, data=data)}
|
||||
|
||||
|
||||
@app.post('/{projectId}/sessions/{sessionId}/heatmaps/url', tags=["heatmaps"])
|
||||
@app.post('/{projectId}/sessions/{sessionId}/heatmaps', tags=["heatmaps"])
|
||||
def get_heatmaps_by_session_id_url(projectId: int, sessionId: int,
|
||||
data: schemas.GetHeatmapBasePayloadSchema = Body(...),
|
||||
context: schemas.CurrentContext = Depends(OR_context)):
|
||||
return {"data": heatmaps.get_by_url_and_session_id(project_id=projectId, session_id=sessionId, data=data)}
|
||||
return {"data": heatmaps.get_x_y_by_url_and_session_id(project_id=projectId, session_id=sessionId, data=data)}
|
||||
|
||||
|
||||
@app.post('/{projectId}/sessions/{sessionId}/clickmaps', tags=["heatmaps"])
|
||||
def get_clickmaps_by_session_id_url(projectId: int, sessionId: int,
|
||||
data: schemas.GetHeatmapBasePayloadSchema = Body(...),
|
||||
context: schemas.CurrentContext = Depends(OR_context)):
|
||||
return {"data": heatmaps.get_selectors_by_url_and_session_id(project_id=projectId, session_id=sessionId, data=data)}
|
||||
|
||||
|
||||
@app.get('/{projectId}/sessions/{sessionId}/favorite', tags=["sessions"])
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ def get_by_url(project_id, data: schemas.GetHeatmapPayloadSchema):
|
|||
return helper.list_to_camel_case(rows)
|
||||
|
||||
|
||||
def get_by_url_and_session_id(project_id, session_id, data: schemas.GetHeatmapBasePayloadSchema):
|
||||
def get_x_y_by_url_and_session_id(project_id, session_id, data: schemas.GetHeatmapBasePayloadSchema):
|
||||
args = {"project_id": project_id, "session_id": session_id, "url": data.url}
|
||||
constraints = ["main_events.project_id = toUInt16(%(project_id)s)",
|
||||
"main_events.session_id = %(session_id)s",
|
||||
|
|
@ -120,6 +120,37 @@ def get_by_url_and_session_id(project_id, session_id, data: schemas.GetHeatmapBa
|
|||
return helper.list_to_camel_case(rows)
|
||||
|
||||
|
||||
def get_selectors_by_url_and_session_id(project_id, session_id, data: schemas.GetHeatmapBasePayloadSchema):
|
||||
args = {"project_id": project_id, "session_id": session_id, "url": data.url}
|
||||
constraints = ["main_events.project_id = toUInt16(%(project_id)s)",
|
||||
"main_events.session_id = %(session_id)s",
|
||||
"(main_events.url_hostpath = %(url)s OR main_events.url_path = %(url)s)",
|
||||
"main_events.event_type='CLICK'"]
|
||||
query_from = f"{exp_ch_helper.get_main_events_table(0)} AS main_events"
|
||||
|
||||
with ch_client.ClickHouseClient() as cur:
|
||||
query = cur.format(f"""SELECT main_events.selector AS selector,
|
||||
COUNT(1) AS count
|
||||
FROM {query_from}
|
||||
WHERE {" AND ".join(constraints)}
|
||||
GROUP BY 1
|
||||
ORDER BY count DESC;""", args)
|
||||
logger.debug("---------")
|
||||
logger.debug(query)
|
||||
logger.debug("---------")
|
||||
try:
|
||||
rows = cur.execute(query)
|
||||
except Exception as err:
|
||||
logger.warning("--------- HEATMAP-session_id SEARCH QUERY EXCEPTION CH -----------")
|
||||
logger.warning(query)
|
||||
logger.warning("--------- PAYLOAD -----------")
|
||||
logger.warning(data)
|
||||
logger.warning("--------------------")
|
||||
raise err
|
||||
|
||||
return helper.list_to_camel_case(rows)
|
||||
|
||||
|
||||
if not config("EXP_SESSIONS_SEARCH", cast=bool, default=False):
|
||||
# this part is identical to FOSS
|
||||
SESSION_PROJECTION_COLS = """s.project_id,
|
||||
|
|
|
|||
|
|
@ -446,12 +446,20 @@ def get_heatmaps_by_url(projectId: int, data: schemas.GetHeatmapPayloadSchema =
|
|||
return {"data": heatmaps.get_by_url(project_id=projectId, data=data)}
|
||||
|
||||
|
||||
@app.post('/{projectId}/sessions/{sessionId}/heatmaps/url', tags=["heatmaps"],
|
||||
@app.post('/{projectId}/sessions/{sessionId}/heatmaps', tags=["heatmaps"],
|
||||
dependencies=[OR_scope(Permissions.session_replay)])
|
||||
def get_heatmaps_by_session_id_url(projectId: int, sessionId: int,
|
||||
data: schemas.GetHeatmapBasePayloadSchema = Body(...),
|
||||
context: schemas.CurrentContext = Depends(OR_context)):
|
||||
return {"data": heatmaps.get_by_url_and_session_id(project_id=projectId, session_id=sessionId, data=data)}
|
||||
return {"data": heatmaps.get_x_y_by_url_and_session_id(project_id=projectId, session_id=sessionId, data=data)}
|
||||
|
||||
|
||||
@app.post('/{projectId}/sessions/{sessionId}/clickmaps', tags=["heatmaps"],
|
||||
dependencies=[OR_scope(Permissions.session_replay)])
|
||||
def get_clickmaps_by_session_id_url(projectId: int, sessionId: int,
|
||||
data: schemas.GetHeatmapBasePayloadSchema = Body(...),
|
||||
context: schemas.CurrentContext = Depends(OR_context)):
|
||||
return {"data": heatmaps.get_selectors_by_url_and_session_id(project_id=projectId, session_id=sessionId, data=data)}
|
||||
|
||||
|
||||
@app.get('/{projectId}/sessions/{sessionId}/favorite', tags=["sessions"],
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue