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

feat(django): allow elements chain as string for certain teams #18701

Merged
merged 13 commits into from
Nov 20, 2023
3 changes: 3 additions & 0 deletions posthog/api/decide.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ def get_decide(request: HttpRequest):
if random() < settings.NEW_ANALYTICS_CAPTURE_SAMPLING_RATE:
response["analytics"] = {"endpoint": settings.NEW_ANALYTICS_CAPTURE_ENDPOINT}

if settings.ELEMENT_CHAIN_AS_STRING_TEAMS and str(team.id) in settings.ELEMENT_CHAIN_AS_STRING_TEAMS:
response["elementsChainAsString"] = True

if team.session_recording_opt_in and (
on_permitted_recording_domain(team, request) or not team.recording_domains
):
Expand Down
14 changes: 14 additions & 0 deletions posthog/api/test/test_decide.py
Original file line number Diff line number Diff line change
Expand Up @@ -2991,6 +2991,20 @@ def test_decide_new_capture_activation(self, *args):
self.assertEqual(response.status_code, 200)
self.assertFalse("analytics" in response.json())

@patch("posthog.models.feature_flag.flag_analytics.CACHE_BUCKET_SIZE", 10)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I don't think we need this mock for this test.

def test_decide_element_chain_as_string(self, *args):
self.client.logout()
with self.settings(ELEMENT_CHAIN_AS_STRING_TEAMS={str(self.team.id)}):
response = self._post_decide(api_version=3)
self.assertEqual(response.status_code, 200)
self.assertTrue("elementsChainAsString" in response.json())
self.assertTrue(response.json()["elementsChainAsString"])

with self.settings(ELEMENT_CHAIN_AS_STRING_TEAMS={"0"}):
response = self._post_decide(api_version=3)
self.assertEqual(response.status_code, 200)
self.assertFalse("elementsChainAsString" in response.json())


class TestDatabaseCheckForDecide(BaseTest, QueryMatchingTest):
"""
Expand Down
2 changes: 2 additions & 0 deletions posthog/settings/ingestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@
NEW_ANALYTICS_CAPTURE_ENDPOINT = os.getenv("NEW_CAPTURE_ENDPOINT", "/i/v0/e/")
NEW_ANALYTICS_CAPTURE_TEAM_IDS = get_set(os.getenv("NEW_ANALYTICS_CAPTURE_TEAM_IDS", ""))
NEW_ANALYTICS_CAPTURE_SAMPLING_RATE = get_from_env("NEW_ANALYTICS_CAPTURE_SAMPLING_RATE", type_cast=float, default=1.0)

ELEMENT_CHAIN_AS_STRING_TEAMS = get_set(os.getenv("ELEMENT_CHAIN_AS_STRING_TEAMS", ""))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't aware we had a get_set, could have used that... Nice!

Loading