: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(warehouse-sources): add convertkit segment, growth, sequence email and click tables (#103705)
Tom Owers6df0af8122d7
diff --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 173e00cee291..5e7de485b3d2 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@@ -2013,11 +2013,11 @@ Diffed against: <https://developers.kit.com/llms.txt>- [x] `GET /v4/tags/{id}/subscribers` — tag<->subscriber junction; without it the synced tags table cannot be joined to people (high)- [x] `GET /v4/forms/{id}/subscribers` — form<->subscriber junction, the signup-source attribution table (high)- [x] `GET /v4/sequences/{id}/subscribers` — sequence membership and per-subscriber sequence state (high)-- [ ] `GET /v4/segments` — segment lookup table, entirely unsynced (high)-- [ ] `GET /v4/sequences/{id}/emails (list-sequence-emails)` — the individual emails inside each sequence - line items for the sequences already synced (medium)-- [ ] `GET /v4/broadcasts/{id}/clicks (get-link-clicks-for-a-broadcast)` — per-link click breakdown within a broadcast (medium)+- [x] `GET /v4/segments` — segment lookup table, entirely unsynced (high)+- [x] `GET /v4/sequences/{id}/emails (list-sequence-emails)` — the individual emails inside each sequence - line items for the sequences already synced (medium)+- [x] `GET /v4/broadcasts/{id}/clicks (get-link-clicks-for-a-broadcast)` — per-link click breakdown within a broadcast (medium)- [ ] `GET /v4/subscribers/{id}/stats` — per-subscriber engagement (opens, clicks) for cohort and churn analysis (medium)-- [ ] `GET /v4/account/growth_stats` — subscriber growth, cancellations and net new over a date range (medium)+- [x] `GET /v4/account/growth_stats` — subscriber growth, cancellations and net new over a date range (medium)- [ ] `GET /v4/account/email_stats` — account-level send, open and click totals (medium)- [ ] `GET /v4/posts` — published newsletter posts, the public content catalog (medium)- [ ] `GET /v4/snippets` — reusable content snippets referenced by broadcasts and sequences (low)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/convertkit/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/convertkit/canonical_descriptions.pyindex a576486f54ec..033f3b1873b4 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/convertkit/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/convertkit/canonical_descriptions.py@@ -163,4 +163,54 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"fields": "Custom field values stored for the subscriber.",},},+ "segments": {+ "description": "A segment — a saved group of subscribers, created and managed in the Kit app.",+ "docs_url": "https://developers.kit.com/api-reference/segments/list-segments",+ "columns": {+ "id": "Unique identifier for the segment.",+ "name": "Name of the segment.",+ "created_at": "Date and time the segment was created.",+ },+ },+ "growth_stats": {+ "description": "Account-wide subscriber growth over a date range. Kit defaults to the last 90 days and reports the bounds in the account's sending time zone, not UTC.",+ "docs_url": "https://developers.kit.com/api-reference/accounts/get-growth-stats",+ "columns": {+ "starting": "Start of the period the stats cover.",+ "ending": "End of the period the stats cover.",+ "subscribers": "Total subscribers on the account at the end of the period.",+ "new_subscribers": "Subscribers gained during the period.",+ "cancellations": "Subscribers who unsubscribed during the period.",+ "net_new_subscribers": "New subscribers minus cancellations for the period.",+ },+ },+ "sequence_emails": {+ "description": "An individual email inside a sequence, one step on the journey subscribers take through it.",+ "docs_url": "https://developers.kit.com/api-reference/sequence-emails/list-sequence-emails",+ "columns": {+ "sequence_id": "Identifier of the sequence the email belongs to.",+ "id": "Unique identifier for the sequence email.",+ "subject": "Subject line of the email.",+ "preview_text": "Preview text shown next to the subject in the inbox.",+ "email_address": "Address the email is sent from.",+ "email_template_id": "Identifier of the email template the email uses.",+ "published": "Whether the email is live and sent to subscribers.",+ "position": "Order of the email within the sequence.",+ "delay_value": "How long to wait before sending, in units of delay_unit.",+ "delay_unit": "Unit the delay is measured in (for example days or hours).",+ "send_days": "Days of the week the email is allowed to send on.",+ },+ },+ "broadcast_clicks": {+ "description": "Click performance for one link in a broadcast.",+ "docs_url": "https://developers.kit.com/api-reference/broadcasts/get-link-clicks-for-a-broadcast",+ "columns": {+ "broadcast_id": "Identifier of the broadcast the link appeared in.",+ "id": "Unique identifier for the link.",+ "url": "Destination the link points to.",+ "unique_clicks": "Number of subscribers who clicked the link at least once.",+ "click_to_delivery_rate": "Percentage of delivered emails whose recipient clicked the link.",+ "click_to_open_rate": "Percentage of opened emails whose recipient clicked the link.",+ },+ },}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/convertkit/convertkit.py b/products/warehouse_sources/backend/temporal/data_imports/sources/convertkit/convertkit.pyindex a957ca8f208b..266cf8f21164 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/convertkit/convertkit.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/convertkit/convertkit.py@@ -124,7 +124,7 @@ def _build_params(db_incremental_field_last_value: Any,incremental_field: str | None,) -> dict[str, Any]:- params: dict[str, Any] = {"per_page": config.page_size}+ params: dict[str, Any] = {"per_page": config.page_size} if config.paginated else {}params.update(config.extra_params)if (diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/convertkit/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/convertkit/settings.pyindex f9cb5eccae16..59f4c870cbd9 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/convertkit/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/convertkit/settings.py@@ -29,6 +29,9 @@ class ConvertKitEndpointConfig:# Static query params always sent to the endpoint (e.g. status=all to include every record).extra_params: dict[str, str] = field(default_factory=dict)page_size: int = DEFAULT_PAGE_SIZE+ # Cleared for a path that returns one object instead of a page, so no paging params are+ # sent to an endpoint that documents none.+ paginated: bool = True# Set where the endpoint is only reachable per parent record, so rows are collected by# walking the parent listing first.fanout: Optional[DependentEndpointConfig] = None@@ -94,6 +97,12 @@ CONVERTKIT_ENDPOINTS: dict[str, ConvertKitEndpointConfig] = {path="/v4/custom_fields",data_key="custom_fields",),+ "segments": ConvertKitEndpointConfig(+ name="segments",+ path="/v4/segments",+ data_key="segments",+ partition_key="created_at",+ ),"purchases": ConvertKitEndpointConfig(name="purchases",path="/v4/purchases",@@ -113,6 +122,48 @@ CONVERTKIT_ENDPOINTS: dict[str, ConvertKitEndpointConfig] = {# Opens and clicks keep accumulating after a broadcast is sent, so the sent_after# window would freeze the numbers of every broadcast already synced.),+ "growth_stats": ConvertKitEndpointConfig(+ name="growth_stats",+ path="/v4/account/growth_stats",+ # A single object, not a list: one row covering the window the request asked for.+ data_key="stats",+ # Kit defaults the window to the last 90 days ending today, and reports both bounds in+ # the account's sending time zone rather than UTC.+ primary_keys=["starting", "ending"],+ paginated=False,+ ),+ "sequence_emails": ConvertKitEndpointConfig(+ name="sequence_emails",+ path="/v4/sequences/{sequence_id}/emails",+ data_key="emails",+ # Kit does not document whether an email id is unique account-wide or only within its+ # sequence, so the parent id stays in the key.+ primary_keys=["sequence_id", "id"],+ fanout=DependentEndpointConfig(+ parent_name="sequences",+ resolve_param="sequence_id",+ resolve_field="id",+ include_from_parent=["id"],+ parent_field_renames={"id": "sequence_id"},+ ),+ ),+ "broadcast_clicks": ConvertKitEndpointConfig(+ name="broadcast_clicks",+ path="/v4/broadcasts/{broadcast_id}/clicks",+ # The links sit under the broadcast the request named.+ data_key="broadcast.clicks",+ primary_keys=["broadcast_id", "id"],+ fanout=DependentEndpointConfig(+ parent_name="broadcasts",+ resolve_param="broadcast_id",+ resolve_field="id",+ include_from_parent=["id"],+ parent_field_renames={"id": "broadcast_id"},+ # The parent listing includes drafts and scheduled broadcasts, which were never+ # sent and have no click record to return.+ child_response_actions=[{"status_code": 404, "action": "ignore"}],+ ),+ ),"form_subscribers": ConvertKitEndpointConfig(name="form_subscribers",path="/v4/forms/{form_id}/subscribers",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/convertkit/tests/test_convertkit.py b/products/warehouse_sources/backend/temporal/data_imports/sources/convertkit/tests/test_convertkit.pyindex e060f026c960..7bac97404110 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/convertkit/tests/test_convertkit.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/convertkit/tests/test_convertkit.py@@ -22,17 +22,22 @@ CONVERTKIT_SESSION_PATCH = ()-def _page(key: str, ids: list[int], *, has_next: bool, end_cursor: str | None) -> Response:- body: dict[str, Any] = {- key: [{"id": i} for i in ids],- "pagination": {"has_next_page": has_next, "end_cursor": end_cursor},- }+def _json_response(body: dict[str, Any], status_code: int = 200) -> Response:resp = Response()- resp.status_code = 200+ resp.status_code = status_coderesp._content = json.dumps(body).encode()return resp+def _page(key: str, ids: list[int], *, has_next: bool, end_cursor: str | None) -> Response:+ return _json_response(+ {+ key: [{"id": i} for i in ids],+ "pagination": {"has_next_page": has_next, "end_cursor": end_cursor},+ }+ )++def _make_manager(resume_state: ConvertKitResumeConfig | None = None) -> mock.MagicMock:manager = mock.MagicMock()manager.can_resume.return_value = resume_state is not None@@ -522,3 +527,94 @@ class TestValidateFanoutCredentials:# The child path carries an unresolved id placeholder, so probing it would 404 and# report a working key as broken.assert mock_session.return_value.get.call_args.args[0] == "https://api.kit.com/v4/forms?per_page=1"+++class TestGrowthStats:+ @mock.patch(CLIENT_SESSION_PATCH)+ def test_yields_the_single_stats_object_without_paging(self, MockSession) -> None:+ session = MockSession.return_value+ stats = {+ "cancellations": 1,+ "net_new_subscribers": 2,+ "new_subscribers": 3,+ "subscribers": 40,+ "starting": "2026-02-10T00:00:00-05:00",+ "ending": "2026-02-24T23:59:59-05:00",+ }+ calls = _wire_calls(session, [_json_response({"stats": stats})])++ rows = _rows(_source("growth_stats", _make_manager()))++ # One row out of an object body, and the run stops on a response carrying no+ # pagination envelope — a second request would exhaust the wired responses.+ assert rows == [stats]+ assert calls[0][0].endswith("/v4/account/growth_stats")+ assert "per_page" not in calls[0][1]+++class TestSequenceEmails:+ @mock.patch(CLIENT_SESSION_PATCH)+ def test_fans_out_over_sequences_and_keys_rows_by_sequence(self, MockSession) -> None:+ session = MockSession.return_value+ calls = _wire_calls(+ session,+ [+ _page("sequences", [11, 12], has_next=False, end_cursor=None),+ _page("emails", [1], has_next=False, end_cursor=None),+ _page("emails", [2], has_next=False, end_cursor=None),+ ],+ )++ rows = _rows(_source("sequence_emails", _make_manager()))++ assert [(r["sequence_id"], r["id"]) for r in rows] == [(11, 1), (12, 2)]+ assert calls[1][0].endswith("/v4/sequences/11/emails")+ assert calls[2][0].endswith("/v4/sequences/12/emails")+++def _clicks_page(broadcast_id: int, link_ids: list[int]) -> Response:+ return _json_response(+ {+ "broadcast": {+ "id": broadcast_id,+ "clicks": [{"id": i, "url": f"https://example.com/{i}", "unique_clicks": i} for i in link_ids],+ },+ "pagination": {"has_next_page": False, "end_cursor": None},+ }+ )+++class TestBroadcastClicks:+ @mock.patch(CLIENT_SESSION_PATCH)+ def test_reads_the_nested_click_list_and_injects_the_broadcast_id(self, MockSession) -> None:+ session = MockSession.return_value+ calls = _wire_calls(+ session,+ [+ _page("broadcasts", [11, 12], has_next=False, end_cursor=None),+ _clicks_page(11, [51, 52]),+ _clicks_page(12, [53]),+ ],+ )++ rows = _rows(_source("broadcast_clicks", _make_manager()))++ assert [(r["broadcast_id"], r["id"]) for r in rows] == [(11, 51), (11, 52), (12, 53)]+ assert rows[0]["url"] == "https://example.com/51"+ assert calls[1][0].endswith("/v4/broadcasts/11/clicks")++ @mock.patch(CLIENT_SESSION_PATCH)+ def test_a_broadcast_with_no_click_record_does_not_fail_the_fan_out(self, MockSession) -> None:+ session = MockSession.return_value+ _wire_calls(+ session,+ [+ _page("broadcasts", [11, 12], has_next=False, end_cursor=None),+ _json_response({"errors": ["Not Found"]}, status_code=404),+ _clicks_page(12, [53]),+ ],+ )++ rows = _rows(_source("broadcast_clicks", _make_manager()))++ assert [(r["broadcast_id"], r["id"]) for r in rows] == [(12, 53)]