Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restore path custom events #2923

Merged
merged 2 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ee/clickhouse/sql/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@
tag_regex=EXTRACT_TAG_REGEX, text_regex=EXTRACT_TEXT_REGEX
)

GET_CUSTOM_EVENTS = """
SELECT DISTINCT event FROM events where team_id = %(team_id)s AND event NOT IN ['$autocapture', '$pageview', '$identify', '$pageleave', '$screen']
"""

GET_PROPERTIES_VOLUME = """
SELECT arrayJoin(array_property_keys) as key, count(1) as count FROM events_with_array_props_view WHERE team_id = %(team_id)s AND timestamp > %(timestamp)s GROUP BY key ORDER BY count DESC
"""
Expand Down
12 changes: 10 additions & 2 deletions ee/clickhouse/views/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
from ee.clickhouse.queries.clickhouse_session_recording import SessionRecording
from ee.clickhouse.queries.sessions.list import SESSIONS_LIST_DEFAULT_LIMIT, ClickhouseSessionsList
from ee.clickhouse.queries.util import parse_timestamps
from ee.clickhouse.sql.events import SELECT_EVENT_WITH_ARRAY_PROPS_SQL, SELECT_EVENT_WITH_PROP_SQL, SELECT_ONE_EVENT_SQL
from ee.clickhouse.sql.events import (
GET_CUSTOM_EVENTS,
SELECT_EVENT_WITH_ARRAY_PROPS_SQL,
SELECT_EVENT_WITH_PROP_SQL,
SELECT_ONE_EVENT_SQL,
)
from posthog.api.event import EventViewSet
from posthog.models import Filter, Person, Team
from posthog.models.action import Action
Expand Down Expand Up @@ -108,7 +113,10 @@ def values(self, request: Request, **kwargs) -> Response:
team = self.team
result = []
flattened = []
if key:
if key == "custom_event":
events = sync_execute(GET_CUSTOM_EVENTS, {"team_id": team.pk})
return Response([{"name": event[0]} for event in events])
elif key:
result = get_property_values_for_key(key, team, value=request.GET.get("value"))
for value in result:
try:
Expand Down
11 changes: 11 additions & 0 deletions posthog/api/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Any, Dict, List, Optional, Union, cast

from django.db.models import Prefetch, QuerySet
from django.db.models.query_utils import Q
from django.utils import timezone
from django.utils.timezone import now
from rest_framework import request, response, serializers, viewsets
Expand Down Expand Up @@ -208,6 +209,16 @@ def values(self, request: request.Request, **kwargs) -> response.Response:
def get_values(self, request: request.Request) -> List[Dict[str, Any]]:
key = request.GET.get("key")
params: List[Optional[Union[str, int]]] = [key, key]

if key == "custom_event":
event_names = (
Event.objects.filter(team_id=self.team_id)
.filter(~Q(event__in=["$autocapture", "$pageview", "$identify", "$pageleave", "$screen"]))
.values("event")
.distinct()
)
return [{"name": value["event"]} for value in event_names]

if request.GET.get("value"):
where = " AND properties ->> %s LIKE %s"
params.append(key)
Expand Down
12 changes: 12 additions & 0 deletions posthog/api/test/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ def _movie_event(self, distinct_id: str):
)
return sign_up

def test_custom_event_values(self):
events = ["test", "new event", "another event"]
for event in events:
event_factory(
distinct_id="bla",
event=event,
team=self.team,
properties={"random_prop": "don't include", "some other prop": "with some text"},
)
response = self.client.get("/api/event/values/?key=custom_event").json()
self.assertListEqual(sorted(events), sorted([event["name"] for event in response]))

def test_event_property_values(self):

with freeze_time("2020-01-10"):
Expand Down