Example #1
0
    def test_steps_with_custom_steps_parameter_are_equivalent_to_funnel_step(self):
        self._create_sample_data_multiple_dropoffs()
        data = {
            "insight": INSIGHT_FUNNELS,
            "interval": "day",
            "date_from": "2021-05-01 00:00:00",
            "date_to": "2021-05-07 00:00:00",
            "funnel_window_days": 7,
            "events": [
                {"id": "step one", "order": 0},
                {"id": "step two", "order": 1},
                {"id": "step three", "order": 2},
            ],
        }
        base_filter = Filter(data=data)

        parameters = [
            #  funnel_step,  custom_steps, expected_results
            (1, [1, 2, 3], 35),
            (2, [2, 3], 15),
            (3, [3], 5),
            (-2, [1], 20),
            (-3, [2], 10),
        ]

        for funnel_step, custom_steps, expected_count in parameters:
            filter = base_filter.with_data({"funnel_step": funnel_step})
            _, results = ClickhouseFunnelActors(filter, self.team).get_actors()

            new_filter = base_filter.with_data({"funnel_custom_steps": custom_steps})
            _, new_results = ClickhouseFunnelActors(new_filter, self.team).get_actors()

            self.assertEqual(new_results, results)
            self.assertEqual(len(results), expected_count)
Example #2
0
    def test_first_step_breakdowns_with_multi_property_breakdown(self):
        person1, person2 = self._create_browser_breakdown_events()
        filter = Filter(
            data={
                "insight": INSIGHT_FUNNELS,
                "date_from": "2020-01-01",
                "date_to": "2020-01-08",
                "interval": "day",
                "funnel_window_days": 7,
                "funnel_step": 1,
                "events": [{"id": "sign up", "order": 0}, {"id": "play movie", "order": 1}, {"id": "buy", "order": 2}],
                "breakdown_type": "event",
                "breakdown": ["$browser", "$browser_version"],
            }
        )
        _, results = ClickhouseFunnelActors(filter, self.team).get_actors()

        self.assertCountEqual([val["id"] for val in results], [person1.uuid, person2.uuid])

        _, results = ClickhouseFunnelActors(
            filter.with_data({"funnel_step_breakdown": "Chrome"}), self.team
        ).get_actors()

        self.assertCountEqual([val["id"] for val in results], [person1.uuid])

        _, results = ClickhouseFunnelActors(
            filter.with_data({"funnel_step_breakdown": "Safari"}), self.team
        ).get_actors()
        self.assertCountEqual([val["id"] for val in results], [person2.uuid])
Example #3
0
    def test_steps_with_custom_steps_parameter_where_funnel_step_equivalence_isnt_possible(self):
        self._create_sample_data_multiple_dropoffs()
        data = {
            "insight": INSIGHT_FUNNELS,
            "interval": "day",
            "date_from": "2021-05-01 00:00:00",
            "date_to": "2021-05-07 00:00:00",
            "funnel_window_days": 7,
            "events": [
                {"id": "step one", "order": 0},
                {"id": "step two", "order": 1},
                {"id": "step three", "order": 2},
            ],
        }
        base_filter = Filter(data=data)

        parameters = [
            # custom_steps, expected_results
            ([1, 2], 30),
            ([1, 3], 25),
            ([3, 1], 25),
            ([1, 3, 3, 1], 25),
        ]

        for custom_steps, expected_count in parameters:
            new_filter = base_filter.with_data({"funnel_custom_steps": custom_steps})
            _, new_results = ClickhouseFunnelActors(new_filter, self.team).get_actors()

            self.assertEqual(len(new_results), expected_count)
Example #4
0
 def get_path_query_funnel_cte(self, funnel_filter: Filter):
     funnel_persons_generator = ClickhouseFunnelActors(
         funnel_filter,
         self._team,
         include_timestamp=bool(self._filter.funnel_paths),
         include_preceding_timestamp=self._filter.funnel_paths ==
         FUNNEL_PATH_BETWEEN_STEPS,
     )
     funnel_persons_query, funnel_persons_param = funnel_persons_generator.actor_query(
         limit_actors=False)
     funnel_persons_query_new_params = funnel_persons_query.replace(
         "%(", "%(funnel_")
     new_funnel_params = {
         "funnel_" + str(key): val
         for key, val in funnel_persons_param.items()
     }
     self.params.update(new_funnel_params)
     return f"""
Example #5
0
    def test_basic_offset(self):
        self._create_sample_data()
        data = {
            "insight": INSIGHT_FUNNELS,
            "interval": "day",
            "date_from": "2021-05-01 00:00:00",
            "date_to": "2021-05-07 00:00:00",
            "funnel_window_days": 7,
            "funnel_step": 1,
            "events": [
                {"id": "step one", "order": 0},
                {"id": "step two", "order": 1},
                {"id": "step three", "order": 2},
            ],
        }

        filter = Filter(data=data)
        _, results = ClickhouseFunnelActors(filter, self.team).get_actors()
        self.assertEqual(100, len(results))

        filter_offset = Filter(data={**data, "offset": 100,})
        _, results = ClickhouseFunnelActors(filter_offset, self.team).get_actors()
        self.assertEqual(10, len(results))
Example #6
0
    def test_first_step_breakdown_person(self):
        person1, person2 = self._create_browser_breakdown_events()
        filter = Filter(
            data={
                "insight": INSIGHT_FUNNELS,
                "date_from": "2020-01-01",
                "date_to": "2020-01-08",
                "interval": "day",
                "funnel_window_days": 7,
                "funnel_step": 1,
                "events": [{"id": "sign up", "order": 0}, {"id": "play movie", "order": 1}, {"id": "buy", "order": 2}],
                "breakdown_type": "person",
                "breakdown": "$country",
            }
        )

        _, results = ClickhouseFunnelActors(filter, self.team).get_actors()
        self.assertCountEqual([val["id"] for val in results], [person1.uuid, person2.uuid])

        _, results = ClickhouseFunnelActors(filter.with_data({"funnel_step_breakdown": "EE"}), self.team).get_actors()
        self.assertCountEqual([val["id"] for val in results], [person2.uuid])

        # Check custom_steps give same answers for breakdowns
        _, custom_step_results = ClickhouseFunnelActors(
            filter.with_data({"funnel_step_breakdown": "EE", "funnel_custom_steps": [1, 2, 3]}), self.team
        ).get_actors()
        self.assertEqual(results, custom_step_results)

        _, results = ClickhouseFunnelActors(filter.with_data({"funnel_step_breakdown": "PL"}), self.team).get_actors()
        self.assertCountEqual([val["id"] for val in results], [person1.uuid])

        # Check custom_steps give same answers for breakdowns
        _, custom_step_results = ClickhouseFunnelActors(
            filter.with_data({"funnel_step_breakdown": "PL", "funnel_custom_steps": [1, 2, 3]}), self.team
        ).get_actors()
        self.assertEqual(results, custom_step_results)
Example #7
0
 def test_second_step_dropoff(self):
     self._create_sample_data_multiple_dropoffs()
     data = {
         "insight": INSIGHT_FUNNELS,
         "interval": "day",
         "date_from": "2021-05-01 00:00:00",
         "date_to": "2021-05-07 00:00:00",
         "funnel_window_days": 7,
         "funnel_step": -2,
         "events": [
             {"id": "step one", "order": 0},
             {"id": "step two", "order": 1},
             {"id": "step three", "order": 2},
         ],
     }
     filter = Filter(data=data)
     _, results = ClickhouseFunnelActors(filter, self.team).get_actors()
     self.assertEqual(20, len(results))
Example #8
0
    def test_steps_with_custom_steps_parameter_overrides_funnel_step(self):
        self._create_sample_data_multiple_dropoffs()
        data = {
            "insight": INSIGHT_FUNNELS,
            "interval": "day",
            "date_from": "2021-05-01 00:00:00",
            "date_to": "2021-05-07 00:00:00",
            "funnel_window_days": 7,
            "funnel_step": 1,  # means custom steps = [1,2,3]
            "funnel_custom_steps": [3],
            "events": [
                {"id": "step one", "order": 0},
                {"id": "step two", "order": 1},
                {"id": "step three", "order": 2},
            ],
        }

        _, results = ClickhouseFunnelActors(Filter(data=data), self.team).get_actors()

        self.assertEqual(len(results), 5)
Example #9
0
 def test_funnel_cohort_breakdown_persons(self):
     person = _create_person(distinct_ids=[f"person1"], team_id=self.team.pk, properties={"key": "value"})
     _create_event(
         team=self.team, event="sign up", distinct_id=f"person1", properties={}, timestamp="2020-01-02T12:00:00Z",
     )
     cohort = Cohort.objects.create(
         team=self.team,
         name="test_cohort",
         groups=[{"properties": [{"key": "key", "value": "value", "type": "person"}]}],
     )
     filters = {
         "events": [{"id": "sign up", "order": 0}, {"id": "play movie", "order": 1}, {"id": "buy", "order": 2}],
         "insight": INSIGHT_FUNNELS,
         "date_from": "2020-01-01",
         "date_to": "2020-01-08",
         "funnel_window_days": 7,
         "funnel_step": 1,
         "breakdown_type": "cohort",
         "breakdown": [cohort.pk],
     }
     filter = Filter(data=filters)
     _, results = ClickhouseFunnelActors(filter, self.team).get_actors()
     self.assertEqual(results[0]["id"], person.uuid)
Example #10
0
    def test_funnel_person_recordings(self):
        p1 = _create_person(distinct_ids=[f"user_1"], team=self.team)
        _create_event(
            event="step one",
            distinct_id="user_1",
            team=self.team,
            timestamp=timezone.now().strftime("%Y-%m-%d %H:%M:%S.%f"),
            properties={"$session_id": "s1", "$window_id": "w1"},
            event_uuid="11111111-1111-1111-1111-111111111111",
        )
        _create_event(
            event="step two",
            distinct_id="user_1",
            team=self.team,
            timestamp=(timezone.now() + timedelta(days=1)).strftime("%Y-%m-%d %H:%M:%S.%f"),
            properties={"$session_id": "s2", "$window_id": "w2"},
            event_uuid="21111111-1111-1111-1111-111111111111",
        )
        _create_session_recording_event(self.team.pk, "user_1", "s2", datetime(2021, 1, 3, 0, 0, 0))

        # First event, but no recording
        filter = Filter(
            data={
                "insight": INSIGHT_FUNNELS,
                "date_from": "2021-01-01",
                "date_to": "2021-01-08",
                "interval": "day",
                "funnel_window_days": 7,
                "funnel_step": 1,
                "events": [
                    {"id": "step one", "order": 0},
                    {"id": "step two", "order": 1},
                    {"id": "step three", "order": 2},
                ],
                "include_recordings": "true",
            }
        )
        _, results = ClickhouseFunnelActors(filter, self.team).get_actors()
        self.assertEqual(results[0]["id"], p1.uuid)
        self.assertEqual(results[0]["matched_recordings"], [])

        # Second event, with recording
        filter = Filter(
            data={
                "insight": INSIGHT_FUNNELS,
                "date_from": "2021-01-01",
                "date_to": "2021-01-08",
                "interval": "day",
                "funnel_window_days": 7,
                "funnel_step": 2,
                "events": [
                    {"id": "step one", "order": 0},
                    {"id": "step two", "order": 1},
                    {"id": "step three", "order": 2},
                ],
                "include_recordings": "true",
            }
        )
        _, results = ClickhouseFunnelActors(filter, self.team).get_actors()
        self.assertEqual(results[0]["id"], p1.uuid)
        self.assertEqual(
            results[0]["matched_recordings"],
            [
                {
                    "session_id": "s2",
                    "events": [
                        {
                            "uuid": UUID("21111111-1111-1111-1111-111111111111"),
                            "timestamp": timezone.now() + timedelta(days=1),
                            "window_id": "w2",
                        }
                    ],
                }
            ],
        )

        # Third event dropoff, with recording
        filter = Filter(
            data={
                "insight": INSIGHT_FUNNELS,
                "date_from": "2021-01-01",
                "date_to": "2021-01-08",
                "interval": "day",
                "funnel_window_days": 7,
                "funnel_step": -3,
                "events": [
                    {"id": "step one", "order": 0},
                    {"id": "step two", "order": 1},
                    {"id": "step three", "order": 2},
                ],
                "include_recordings": "true",
            }
        )
        _, results = ClickhouseFunnelActors(filter, self.team).get_actors()
        self.assertEqual(results[0]["id"], p1.uuid)
        self.assertEqual(
            results[0]["matched_recordings"],
            [
                {
                    "session_id": "s2",
                    "events": [
                        {
                            "uuid": UUID("21111111-1111-1111-1111-111111111111"),
                            "timestamp": timezone.now() + timedelta(days=1),
                            "window_id": "w2",
                        }
                    ],
                }
            ],
        )