: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 klaviyo suppression and consent coverage (#80004)
jake sciotto26e8ff1ff20e
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/klaviyo/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/klaviyo/canonical_descriptions.pyindex 03e5f21631d0..436d4d28e744 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/klaviyo/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/klaviyo/canonical_descriptions.py@@ -141,7 +141,10 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {},},"profiles": {- "description": "A profile in Klaviyo representing a person you can message and track.",+ "description": (+ "A profile in Klaviyo representing a person you can message and track. Includes consent "+ "and suppression status per channel in the subscriptions column."+ ),"docs_url": "https://developers.klaviyo.com/en/reference/get_profiles","columns": {"id": "Unique identifier for the profile.",@@ -153,6 +156,18 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"organization": "The organization the profile is associated with.","title": "The profile's job title.","location": "The profile's location details.",+ "subscriptions": (+ "The profile's consent and suppression status per channel, stored as JSON and "+ "requested by default. `email.marketing` holds `consent`, "+ "`can_receive_email_marketing`, `suppression` (global suppressions as "+ "{reason, timestamp} entries, with reason one of HARD_BOUNCE, INVALID_EMAIL, "+ "SPAM_COMPLAINT, UNSUBSCRIBE, or USER_SUPPRESSED), and `list_suppressions` "+ "(per-list suppressions as {list_id, reason, timestamp} entries). `sms.marketing` "+ "and `sms.transactional` hold `consent`, `consent_timestamp`, and a `can_receive_*` "+ "flag, while `mobile_push.marketing` holds `consent` and `can_receive_push_marketing`. Use "+ "this column to export unsubscribe, suppression, and consent state, e.g. when "+ "migrating to another sending platform."+ ),"properties": ("Custom properties set on the profile. Subscription status lives here in the `$consent` array ""— the communication channels (`sms`, `email`, and/or `push`) the profile is currently "@@ -172,7 +187,9 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"from a list are only pruned by a full refresh. List membership is not the same as subscription: ""a profile can be on a list without being subscribed to any channel. To tell which channels ""(`sms`, `email`, and/or `push`) a profile is actually subscribed to, check the `$consent` array "- "in the profile's `properties` (in the `profiles` table)."+ "in the profile's `properties` (in the `profiles` table). To tell which profiles are suppressed "+ "for a specific list, use the `profiles` table's `subscriptions` column: "+ "`email.marketing.list_suppressions` records {list_id, reason, timestamp} per suppression."),"docs_url": "https://developers.klaviyo.com/en/reference/get_profiles_for_list","columns": {diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/klaviyo/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/klaviyo/settings.pyindex 4f8361e62e1d..a3404eec59ab 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/klaviyo/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/klaviyo/settings.py@@ -240,6 +240,12 @@ KLAVIYO_ENDPOINTS: dict[str, KlaviyoEndpointConfig] = {"field_type": IncrementalFieldType.DateTime,},],+ description=(+ "Includes each profile's subscriptions object by default: consent status per channel "+ "(email, sms, push), global email suppressions in "+ "subscriptions.email.marketing.suppression, and per-list email suppressions in "+ "subscriptions.email.marketing.list_suppressions"+ ),),# Klaviyo only exposes list membership through per-list endpoints (which can't be called from# HogQL), so the many-to-many can't be joined. This table fans out one paginated request per list@@ -282,7 +288,8 @@ KLAVIYO_ENDPOINTS: dict[str, KlaviyoEndpointConfig] = {"Incremental syncs pick up new joins and re-joins; profiles removed from a list are only ""reflected on a full refresh. List membership is not the same as subscription: check the ""$consent array in the profiles table's properties column to see which channels (sms, "- "email, push) a profile is currently subscribed to"+ "email, push) a profile is currently subscribed to. Per-list email suppressions are in "+ "the profiles table's subscriptions column, under email.marketing.list_suppressions"),),# Segment membership has the same shape as list membership: Klaviyo only exposes it per segment,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/klaviyo/test_klaviyo.py b/products/warehouse_sources/backend/temporal/data_imports/sources/klaviyo/test_klaviyo.pyindex 4fdccb8df8af..68bb2106eb8e 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/klaviyo/test_klaviyo.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/klaviyo/test_klaviyo.py@@ -758,6 +758,59 @@ class TestGeneralizedFanOut:assert KLAVIYO_ENDPOINTS[endpoint].primary_keys == expected_keys+class TestProfilesSubscriptionsRoundTrip:+ def test_suppression_and_consent_land_in_the_synced_row(self, monkeypatch: Any) -> None:+ # Suppression and consent status only exist inside the nested subscriptions object; if+ # flattening or batching drops or reshapes it, a team exporting unsubscribes before a+ # sending-platform migration silently loses exactly the profiles that must not be messaged.+ suppressed_subscriptions = {+ "email": {+ "marketing": {+ "can_receive_email_marketing": False,+ "consent": "UNSUBSCRIBED",+ "suppression": [{"reason": "USER_SUPPRESSED", "timestamp": "2026-01-02T00:00:00+00:00"}],+ "list_suppressions": [+ {"list_id": "L1", "reason": "UNSUBSCRIBE", "timestamp": "2026-01-03T00:00:00+00:00"}+ ],+ }+ }+ }+ consented_subscriptions = {+ "email": {"marketing": {"can_receive_email_marketing": True, "consent": "SUBSCRIBED"}},+ "sms": {+ "marketing": {+ "can_receive_sms_marketing": True,+ "consent": "SUBSCRIBED",+ "consent_timestamp": "2026-02-01T00:00:00+00:00",+ }+ },+ "mobile_push": {"marketing": {"can_receive_push_marketing": False, "consent": "UNSUBSCRIBED"}},+ }+ pages = {+ "https://a.klaviyo.com/api/profiles?additional-fields[profile]=subscriptions": {+ "data": [+ {+ "type": "profile",+ "id": "P_SUPPRESSED",+ "attributes": {"email": "[email protected]", "subscriptions": suppressed_subscriptions},+ },+ {+ "type": "profile",+ "id": "P_CONSENTED",+ "attributes": {"email": "[email protected]", "subscriptions": consented_subscriptions},+ },+ ],+ "links": {"next": None},+ },+ }++ rows = {row["id"]: row for row in _collect_rows("profiles", monkeypatch, pages)}++ assert rows["P_SUPPRESSED"]["email"] == "[email protected]"+ assert json.loads(rows["P_SUPPRESSED"]["subscriptions"]) == suppressed_subscriptions+ assert json.loads(rows["P_CONSENTED"]["subscriptions"]) == consented_subscriptions++class TestValuesReports:@staticmethoddef _pages(report_path: str, results: list[dict], next_url: str | None = None) -> dict[str, Any]: