Skip to content

Commit

Permalink
feat(django): allow elements chain as string for certain teams (#18701)
Browse files Browse the repository at this point in the history
* Adding flag in decide response to allow returning elements chain as a string; related PR: PostHog/posthog-js#823

* Created a separate env var to control this behavior in https://github.com/PostHog/posthog-cloud-infra/pull/2314

* Update query snapshots

* Add env var

* Update query snapshots

* Formatting

* Just use a boolean

* Add test for when ELEMENT_CHAIN_AS_STRING_TEAMS is set and not set

* Fix test

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
David Murphy and github-actions[bot] authored Nov 20, 2023
1 parent 2a3945b commit 73efda3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions posthog/api/decide.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,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
13 changes: 13 additions & 0 deletions posthog/api/test/test_decide.py
Original file line number Diff line number Diff line change
Expand Up @@ -3006,6 +3006,19 @@ def test_decide_new_capture_activation(self, *args):
self.assertEqual(response.status_code, 200)
self.assertFalse("analytics" in response.json())

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 @@ -38,3 +38,5 @@
NEW_ANALYTICS_CAPTURE_TEAM_IDS = get_set(os.getenv("NEW_ANALYTICS_CAPTURE_TEAM_IDS", ""))
NEW_ANALYTICS_CAPTURE_EXCLUDED_TEAM_IDS = get_set(os.getenv("NEW_ANALYTICS_CAPTURE_EXCLUDED_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", ""))

0 comments on commit 73efda3

Please sign in to comment.