Skip to content
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
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]"},
{name = "Mark Boom", email = "[email protected]"},
{name = "Gautam Aggrawal", email = "[email protected]"},
]
license = {text = "MIT"}
readme = "README.md"
Expand Down
67 changes: 0 additions & 67 deletions src/py_mixpanel/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
96 changes: 0 additions & 96 deletions tests/py_mixpanel/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]"
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 = "[email protected]"
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 = "[email protected]"
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 = "[email protected]"
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 = "[email protected]"
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]