diff --git a/pyproject.toml b/pyproject.toml index 1702924..d5a3b71 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,11 +4,12 @@ build-backend = "setuptools.build_meta" [project] name = "py-mixpanel" -version = "1.1.0" +version = "1.1.1" description = "Python wrapper for Mixpanel analytics" authors = [ {name = "Mathieu Lamiot", email = "mathieu@wp-media.me"}, {name = "Mark Boom", email = "mark.boom@group.one"}, + {name = "Gautam Aggrawal", email = "gautam.aggrawal@group.one"}, ] license = {text = "MIT"} readme = "README.md" diff --git a/src/py_mixpanel/tracking.py b/src/py_mixpanel/tracking.py index c375fb0..7b95871 100644 --- a/src/py_mixpanel/tracking.py +++ b/src/py_mixpanel/tracking.py @@ -74,70 +74,3 @@ def hash(self, user_id: str) -> str: return user_id return hashlib.sha224(user_id.encode("utf-8")).hexdigest() - - def track_order_placed( - self, - user_id: str, - order_id: str, - product_name: str | None = None, - additional_context: dict[str, t.Any] | None = None, - ) -> None: - """ - Track an Order Placed event. - """ - properties: dict[str, t.Any] = { - "order_id": order_id, - } - - if product_name: - properties["product_name"] = product_name - - if additional_context: - properties.update(additional_context) - - self.track(user_id, "Order Placed", properties) - - def track_sso_link_clicked( - self, - user_id: str, - sso_provider: str | None = None, - redirect_url: str | None = None, - additional_context: dict[str, t.Any] | None = None, - ) -> None: - """ - Track when a user clicks an SSO link. - """ - properties: dict[str, t.Any] = {} - - if sso_provider: - properties["sso_provider"] = sso_provider - - if redirect_url: - properties["redirect_url"] = redirect_url - - if additional_context: - properties.update(additional_context) - - self.track(user_id, "SSO Link Clicked", properties) - - def track_actionable_resolved( - self, - user_id: str, - actionable_id: str, - actionable_type: str | None = None, - additional_context: dict[str, t.Any] | None = None, - ) -> None: - """ - Track when an actionable is resolved. - """ - properties: dict[str, t.Any] = { - "actionable_id": actionable_id, - } - - if actionable_type: - properties["actionable_type"] = actionable_type - - if additional_context: - properties.update(additional_context) - - self.track(user_id, "Actionable Resolved", properties) diff --git a/tests/py_mixpanel/tracking.py b/tests/py_mixpanel/tracking.py index 013d84a..868aee6 100644 --- a/tests/py_mixpanel/tracking.py +++ b/tests/py_mixpanel/tracking.py @@ -154,99 +154,3 @@ def test_hashing_anonymous_user_id(mixpanel_mock: Mock) -> None: tracker = Tracking(ANONYMOUS_USER_ID, enable_tracking=True) assert tracker.hash(ANONYMOUS_USER_ID) == "anonymous" - - -@patch("mixpanel.Mixpanel") -def test_track_order_placed(mixpanel_mock: Mock) -> None: - mixpanel_instance = Mock() - mixpanel_mock.return_value = mixpanel_instance - - tracker = Tracking("abc", enable_tracking=True) - user_id = "user@example.com" - tracker.track_order_placed( - user_id, - "order-123", - product_name="Product A", - additional_context={"product_id": "123"}, - ) - - mixpanel_instance.track.assert_called_once_with( - tracker.hash(user_id), - "Order Placed", - {"order_id": "order-123", "product_name": "Product A", "product_id": "123"}, - ) - - -@patch("mixpanel.Mixpanel") -def test_track_sso_link_clicked(mixpanel_mock: Mock) -> None: - mixpanel_instance = Mock() - mixpanel_mock.return_value = mixpanel_instance - - tracker = Tracking("abc", enable_tracking=True) - user_id = "user@example.com" - tracker.track_sso_link_clicked( - user_id, - sso_provider="Google", - redirect_url="https://example.com", - additional_context={"product_id": "123"}, - ) - - mixpanel_instance.track.assert_called_once_with( - tracker.hash(user_id), - "SSO Link Clicked", - { - "sso_provider": "Google", - "redirect_url": "https://example.com", - "product_id": "123", - }, - ) - - -@patch("mixpanel.Mixpanel") -def test_track_actionable_resolved(mixpanel_mock: Mock) -> None: - mixpanel_instance = Mock() - mixpanel_mock.return_value = mixpanel_instance - - tracker = Tracking("abc", enable_tracking=True) - user_id = "user@example.com" - tracker.track_actionable_resolved( - user_id, - actionable_id="123", - actionable_type="Product", - additional_context={"product_id": "123"}, - ) - - mixpanel_instance.track.assert_called_once_with( - tracker.hash(user_id), - "Actionable Resolved", - {"actionable_id": "123", "actionable_type": "Product", "product_id": "123"}, - ) - - -@patch("mixpanel.Mixpanel") -def test_track_sso_link_clicked_empty_strings(mixpanel_mock: Mock) -> None: - """Test that empty string optional parameters are treated as falsy.""" - mixpanel_instance = Mock() - mixpanel_mock.return_value = mixpanel_instance - - tracker = Tracking("abc", enable_tracking=True) - user_id = "user@example.com" - tracker.track_sso_link_clicked(user_id, sso_provider="", redirect_url="") - - call_args = mixpanel_instance.track.call_args - assert "sso_provider" not in call_args[0][2] - assert "redirect_url" not in call_args[0][2] - - -@patch("mixpanel.Mixpanel") -def test_track_order_placed_empty_string_product_name(mixpanel_mock: Mock) -> None: - """Test empty string product_name is treated as falsy and not included.""" - mixpanel_instance = Mock() - mixpanel_mock.return_value = mixpanel_instance - - tracker = Tracking("abc", enable_tracking=True) - user_id = "user@example.com" - tracker.track_order_placed(user_id, "order-123", product_name="") - - call_args = mixpanel_instance.track.call_args - assert "product_name" not in call_args[0][2]