:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(data-warehouse): add mixmax live feed events table (#115051)
Tom Owers54e5d0a83f60
diff --git a/posthog/test/repo_invariants/dataclass_frozen_baseline.txt b/posthog/test/repo_invariants/dataclass_frozen_baseline.txtindex cd57f18cb4ad..b1d06fe73368 100644--- a/posthog/test/repo_invariants/dataclass_frozen_baseline.txt+++ b/posthog/test/repo_invariants/dataclass_frozen_baseline.txt@@ -801,7 +801,6 @@1 products/warehouse_sources/backend/temporal/data_imports/sources/metorial/metorial.py1 products/warehouse_sources/backend/temporal/data_imports/sources/metorial/settings.py1 products/warehouse_sources/backend/temporal/data_imports/sources/mixmax/mixmax.py-1 products/warehouse_sources/backend/temporal/data_imports/sources/mixmax/settings.py1 products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/mixpanel.py1 products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/settings.py1 products/warehouse_sources/backend/temporal/data_imports/sources/mollie/mollie.pydiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.mdindex 0c209cfb25b2..77b864726ef7 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md@@ -5634,10 +5634,10 @@ Today (14): `appointment_links`, `code_snippets`, `file_requests`, `insights_repDiffed against: <https://developer.mixmax.com/reference>- [ ] `sequence recipients (GET /v1/sequences/{id}/recipients)` — the per-recipient membership and stage state for the sequences we already sync — the core sequence fact table (high)-- [ ] `sent sequences (GET /v1/sequences/sent)` — per-send records with delivery outcome, the transaction table behind sequence performance (high)-- [ ] `contacts (GET /v1/contacts)` — lookup table resolving contact IDs referenced by messages, sequences, and live feed events (high)-- [ ] `live feed events (GET /v1/livefeed/events)` — the individual open/click/reply events; the synced live_feed table is the container, not the events (high)-- [ ] `report data table (POST /v1/reports/data/table)` — Mixmax's own aggregated reporting grid — the vendor's headline metrics (high)+- [ ] `sent sequences (GET /v1/sequences/sent)` — per-send records with delivery outcome, the transaction table behind sequence performance (high). Skipped: the endpoint returns a single count of sequence messages sent in the past 24 hours, not per-send records.+- [ ] `contacts (GET /v1/contacts)` — lookup table resolving contact IDs referenced by messages, sequences, and live feed events (high). Skipped: Mixmax marks `/contacts` as deprecated. Live feed events already carry the recipient email and name.+- [x] `live feed events (GET /v1/livefeed/events)` — the individual open/click/reply events; the synced live_feed table is the container, not the events (high). Added as `live_feed_events` (fan-out over `live_feed` by `messageId`).+- [ ] `report data table (POST /v1/reports/data/table)` — Mixmax's own aggregated reporting grid — the vendor's headline metrics (high). Skipped: an aggregate query whose rows change with the caller's `groupBy` and query string, with no documented row key. The per-message counters are already on `live_feed`.- [ ] `contact groups and their members (GET /v1/contactgroups, GET /v1/contactgroups/{id}/contacts)` — segment definitions plus the membership join to contacts (medium)- [ ] `teams and team members (GET /v1/teams, GET /v1/teams/{id}/members)` — org structure lookup that resolves the user IDs we already sync (medium)- [ ] `unsubscribes (GET /v1/unsubscribes)` — suppression list needed to interpret sequence and message outcomes (medium)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mixmax/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mixmax/canonical_descriptions.pyindex 0c180a4b7f46..d2142e477578 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mixmax/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mixmax/canonical_descriptions.py@@ -76,6 +76,27 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"docs_url": f"{_DOCS}/live-feed","columns": {"uid": "Unique identifier for the live feed event."},},+ "live_feed_events": {+ "description": "Individual tracking events (opens, clicks, downloads, replies) for each live feed message, up to 200 per message.",+ "docs_url": f"{_DOCS}/livefeedevents",+ "columns": {+ "_id": "Unique identifier for the event.",+ "message_id": "Identifier of the live feed message the event belongs to.",+ "type": "The type of event, such as 'opened' or 'replied'.",+ "timestamp": "When the event occurred, in milliseconds since the Unix epoch.",+ "recipientEmail": "Email address of the recipient who triggered the event.",+ "recipientName": "Name of the recipient who triggered the event.",+ "country": "Approximate country where the event occurred. May be null.",+ "region": "Approximate region, state or province where the event occurred. May be null.",+ "city": "Approximate city where the event occurred. May be null.",+ "os": "Operating system the event was triggered from. May be null.",+ "program": "Program or email client the event was triggered from. May be null.",+ "isMobile": "Whether the event was triggered from a mobile device. Approximate. May be null.",+ "linkUrl": "URL of the clicked link. Only present for 'clicked' events.",+ "linkText": "Text of the clicked link. Only present for 'clicked' events.",+ "fileName": "Name of the downloaded file. Only present for 'downloaded' events.",+ },+ },"appointment_links": {"description": "The authenticated user's appointment (scheduling) links.","docs_url": f"{_DOCS}/appointment-links",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mixmax/mixmax.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mixmax/mixmax.pyindex 3fd628ea8fbf..db49783b91ea 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mixmax/mixmax.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mixmax/mixmax.py@@ -16,8 +16,9 @@ Rate limits: 120 requests / 60s per user+IP, `429` with `Retry-After`. The frame"""import dataclasses-from typing import Any, Optional-from urllib.parse import urlencode+from collections.abc import Iterable+from typing import Any, Optional, cast+from urllib.parse import quote, urlencodefrom requests import Response@@ -26,21 +27,25 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.resRESTAPIConfig,rest_api_resource,)+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.fanout import (+ build_dependent_resource,+)from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.paginators import (BaseNextUrlPaginator,+ SinglePagePaginator,)+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import ClientConfigfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManagerfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.source_helpers import validate_via_probefrom products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceResponsefrom products.warehouse_sources.backend.temporal.data_imports.sources.mixmax.settings import (+ MESSAGE_ID_PARAM_FIELD,MIXMAX_ENDPOINTS,+ PAGE_SIZE,MixmaxEndpointConfig,)MIXMAX_BASE_URL = "https://api.mixmax.com/v1"-# Docs default the page size to 50 and cap it around 300; 100 keeps request volume low against the-# 120 req/min ceiling without risking a rejected oversized page.-PAGE_SIZE = 100@dataclasses.dataclass@@ -104,6 +109,56 @@ class MixmaxCursorPaginator(BaseNextUrlPaginator):self._has_next_page = False+def _client_config(api_key: str) -> ClientConfig:+ return {+ "base_url": MIXMAX_BASE_URL,+ # Auth (the `X-API-Token` header) goes through the framework auth config so its value is+ # redacted from logs and error messages; only the non-secret Accept header is set here.+ "headers": {"Accept": "application/json"},+ "auth": {"type": "api_key", "api_key": api_key, "name": "X-API-Token", "location": "header"},+ }+++def _with_encoded_message_id(row: dict[str, Any]) -> dict[str, Any]:+ row[MESSAGE_ID_PARAM_FIELD] = quote(str(row["_id"]), safe="")+ return row+++def _fanout_source(+ api_key: str, endpoint: str, config: MixmaxEndpointConfig, team_id: int, job_id: str+) -> SourceResponse:+ assert config.fanout is not None+ parent_config = MIXMAX_ENDPOINTS[config.fanout.parent_name]++ dependent_resource = cast(+ Iterable[Any],+ build_dependent_resource(+ endpoint_configs=MIXMAX_ENDPOINTS,+ child_endpoint=endpoint,+ fanout=config.fanout,+ client_config=_client_config(api_key),+ path_format_values={},+ team_id=team_id,+ job_id=job_id,+ db_incremental_field_last_value=None,+ # The parent page size rides in `fanout.parent_params`; the child takes no page size.+ page_size_param=None,+ parent_endpoint_extra={"paginator": MixmaxCursorPaginator(parent_config.path), "data_selector": "results"},+ # Child responses are a single `{results: [...]}` page, capped server-side.+ child_endpoint_extra={"paginator": SinglePagePaginator(), "data_selector": "results"},+ parent_data_map=_with_encoded_message_id,+ ),+ )++ return SourceResponse(+ name=endpoint,+ items=lambda: dependent_resource,+ primary_keys=config.primary_keys,+ # Child rows follow the parent's newest-first order.+ sort_mode="desc",+ )++def mixmax_source(api_key: str,endpoint: str,@@ -114,17 +169,14 @@ def mixmax_source() -> SourceResponse:config: MixmaxEndpointConfig = MIXMAX_ENDPOINTS[endpoint]+ if config.fanout is not None:+ return _fanout_source(api_key, endpoint, config, team_id, job_id)+# Single-object `/…/me` endpoints take no pagination params; collections carry the page limit.params: dict[str, Any] = {} if config.single_object else {"limit": PAGE_SIZE}rest_config: RESTAPIConfig = {- "client": {- "base_url": MIXMAX_BASE_URL,- # Auth (the `X-API-Token` header) goes through the framework auth config so its value is- # redacted from logs and error messages; only the non-secret Accept header is set here.- "headers": {"Accept": "application/json"},- "auth": {"type": "api_key", "api_key": api_key, "name": "X-API-Token", "location": "header"},- },+ "client": _client_config(api_key),"resource_defaults": {},"resources": [{diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mixmax/posthog_com_doc.md b/products/warehouse_sources/backend/temporal/data_imports/sources/mixmax/posthog_com_doc.mdindex e36ddfd98ebc..1e492ec139b1 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mixmax/posthog_com_doc.md+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mixmax/posthog_com_doc.md@@ -39,6 +39,8 @@ PostHog authenticates every request with this token (sent as the `X-API-Token` hMixmax's API does not expose a server-side "modified since" filter, so every table is synced as **full refresh** — each sync re-reads the resource and replaces the table. Because of Mixmax's fixed rate limit (120 requests per minute), prefer a modest sync frequency, especially for high-volume tables like the live feed.+The `live_feed_events` table makes one request per live feed message, so it is not selected by default. Enable it only if you need per-event detail, and expect a large live feed to take a while to sync.+## Configuration<SourceParameters />diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mixmax/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mixmax/settings.pyindex e076c6c4b50c..44abe43cf67b 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mixmax/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mixmax/settings.py@@ -1,7 +1,16 @@from dataclasses import dataclass, field+from typing import Any+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.fanout import (+ DependentEndpointConfig,+)-@dataclass+# Docs default the page size to 50 and cap it around 300; 100 keeps request volume low against the+# 120 req/min ceiling without risking a rejected oversized page.+PAGE_SIZE = 100+++@dataclass(frozen=True)class MixmaxEndpointConfig:name: strpath: str@@ -15,6 +24,31 @@ class MixmaxEndpointConfig:# Whether the table is selected for sync by default in the UI.should_sync_default: bool = Truedescription: str | None = None+ fanout: DependentEndpointConfig | None = None+ # The remaining fields exist to satisfy the shared FanoutEndpointLike protocol; no Mixmax+ # endpoint is incremental.+ incremental_fields: list[Any] = field(default_factory=list)+ default_incremental_field: str | None = None+ page_size: int = PAGE_SIZE+++# Parent rows carry their `_id` percent-encoded under this key, because the fan-out binds the+# resolved value into the child URL with no escaping.+MESSAGE_ID_PARAM_FIELD = "_message_id_param"++# /livefeed/events takes a single `messageId` per request, so events fan out over the live feed's+# messages. Event ids are only documented as unique, so the key also carries the parent message id.+_LIVE_FEED_EVENTS_FANOUT = DependentEndpointConfig(+ parent_name="live_feed",+ resolve_param="message_id",+ resolve_field=MESSAGE_ID_PARAM_FIELD,+ include_from_parent=["_id"],+ parent_field_renames={"_id": "message_id"},+ parent_params={"limit": PAGE_SIZE},+ child_params={"wasSentViaMixmax": "true"},+ # A message deleted between the live feed listing and its events fetch 404s; skip it.+ child_response_actions=[{"status_code": 404, "action": "ignore"}],+)# Mixmax exposes no server-side timestamp filter (`updated_after`/`since`), so every endpoint is@@ -77,6 +111,15 @@ MIXMAX_ENDPOINTS: dict[str, MixmaxEndpointConfig] = {primary_keys=["uid"],description="Real-time email tracking events (opens, clicks, downloads). Full refresh only.",),+ "live_feed_events": MixmaxEndpointConfig(+ name="live_feed_events",+ path="/livefeed/events?messageId={message_id}",+ primary_keys=["message_id", "_id"],+ fanout=_LIVE_FEED_EVENTS_FANOUT,+ # One request per live feed message against the 120 req/min limit, so it is opt-in.+ should_sync_default=False,+ description="Individual open, click, download, and reply events for each live feed message (up to 200 per message).",+ ),"appointment_links": MixmaxEndpointConfig(name="appointment_links",path="/appointmentlinks/me",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mixmax/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mixmax/source.pyindex f7e5baff3d79..23d11bab49b3 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mixmax/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mixmax/source.py@@ -31,6 +31,7 @@ from products.warehouse_sources.backend.types import ExternalDataSourceType# endpoint carries incremental fields.MIXMAX_INCREMENTAL_FIELDS: dict[str, list] = {}MIXMAX_DESCRIPTIONS = {name: config.description for name, config in MIXMAX_ENDPOINTS.items() if config.description}+MIXMAX_SHOULD_SYNC_DEFAULT = {name: config.should_sync_default for name, config in MIXMAX_ENDPOINTS.items()}@SourceRegistry.register@@ -105,6 +106,7 @@ API access requires a Growth+ or Enterprise plan with the API feature enabled onMIXMAX_INCREMENTAL_FIELDS,names,descriptions=MIXMAX_DESCRIPTIONS,+ should_sync_default=MIXMAX_SHOULD_SYNC_DEFAULT,)def validate_credentials(diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mixmax/tests/test_mixmax.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mixmax/tests/test_mixmax.pyindex b39a15104101..561ea6d2a626 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mixmax/tests/test_mixmax.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mixmax/tests/test_mixmax.py@@ -144,6 +144,37 @@ class TestPagination:manager.save_state.assert_not_called()+class TestLiveFeedEventsFanout:+ @mock.patch(CLIENT_SESSION_PATCH)+ def test_fetches_events_per_live_feed_message_and_skips_missing_messages(self, MockSession: mock.MagicMock) -> None:+ session = MockSession.return_value+ snaps = _wire(+ session,+ [+ _resp({"results": [{"_id": "m1"}], "next": "cur2", "hasNext": True}),+ _resp({"results": [{"_id": "e1", "type": "opened"}, {"_id": "e2", "type": "replied"}]}),+ _resp({"results": [{"_id": "m2&limit=1"}], "hasNext": False}),+ _resp({}, status=404),+ ],+ )++ rows = _run(session, "live_feed_events", _make_manager())++ assert rows == [+ {"_id": "e1", "type": "opened", "message_id": "m1"},+ {"_id": "e2", "type": "replied", "message_id": "m1"},+ ]+ assert snaps == [+ {"url": "https://api.mixmax.com/v1/livefeed", "params": {"limit": 100}},+ {"url": "https://api.mixmax.com/v1/livefeed/events?messageId=m1", "params": {"wasSentViaMixmax": "true"}},+ {"url": "https://api.mixmax.com/v1/livefeed?limit=100&next=cur2", "params": {}},+ {+ "url": "https://api.mixmax.com/v1/livefeed/events?messageId=m2%26limit%3D1",+ "params": {"wasSentViaMixmax": "true"},+ },+ ]++class TestRetryClassification:@parameterized.expand([("rate_limited", 429), ("server_error", 500), ("bad_gateway", 503)])@mock.patch("tenacity.nap.time.sleep")