Skip to content

: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.

feat(data-warehouse): meta ads ad/adset breakdowns and attribution config (#79895)

posthog[bot]c68f24ade702
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/generated_configs/metaads.py b/products/warehouse_sources/backend/temporal/data_imports/sources/generated_configs/metaads.py
index 68d8d0c96f92..f8d70adf7951 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/generated_configs/metaads.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/generated_configs/metaads.py
@@ -1,6 +1,8 @@
# This file is automatically generated from `SourceRegistry.get_all_sources()`
# Do not edit manually - run `pnpm generate:source-configs` to regenerate.
+from typing import Literal
+
from products.warehouse_sources.backend.temporal.data_imports.sources.common import config
@@ -9,3 +11,5 @@ class MetaAdsSourceConfig(config.Config):
account_id: str
meta_ads_integration_id: int = config.value(converter=config.str_to_int)
sync_lookback_days: int | None = config.value(converter=config.str_to_optional_int, default_factory=lambda: None)
+ use_unified_attribution_setting: Literal["", "true", "false"] | None = config.value(default_factory=lambda: None)
+ action_attribution_windows: str | None = None
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/meta_ads.py b/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/meta_ads.py
index 20c62071761d..d7386fdd1c18 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/meta_ads.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/meta_ads.py
@@ -860,6 +860,33 @@ def _make_paginated_api_request(
yield from _iter_time_range_pagination(url, params, time_range, resume_config, resumable_source_manager)
+def _attribution_params(config: MetaAdsSourceConfig) -> dict[str, str]:
+ """Attribution settings to add to an Insights request, only when the source configures them.
+
+ Omitted entirely when unset, so existing connections keep Meta's default attribution and
+ produce byte-for-byte the same request as before. When set, they let a user reconcile
+ PostHog's spend and conversion numbers with what Ads Manager shows.
+
+ - ``action_attribution_windows``: a comma-separated list in config (e.g. ``7d_click,1d_view``),
+ sent JSON-encoded the way Meta's Graph API accepts a list parameter.
+ - ``use_unified_attribution_setting``: a string flag (``"true"``/``"false"``) sent verbatim;
+ any other value (including the "use Meta's default" empty option) leaves it unset.
+ """
+ params: dict[str, str] = {}
+
+ windows_raw = getattr(config, "action_attribution_windows", None)
+ if windows_raw:
+ windows = [window.strip() for window in windows_raw.split(",") if window.strip()]
+ if windows:
+ params["action_attribution_windows"] = json.dumps(windows)
+
+ use_unified = getattr(config, "use_unified_attribution_setting", None)
+ if use_unified in ("true", "false"):
+ params["use_unified_attribution_setting"] = use_unified
+
+ return params
+
+
def meta_ads_source(
resource_name: str,
config: MetaAdsSourceConfig,
@@ -930,6 +957,10 @@ def meta_ads_source(
"limit": PAGE_LIMIT_FALLBACK_SIZES[0],
**schema.extra_params,
}
+ # Attribution settings apply only to Insights (stats) tables; entity endpoints (campaigns,
+ # ads, ...) don't take them and Meta would reject the extra params.
+ if schema.is_stats:
+ params.update(_attribution_params(config))
yield from _make_paginated_api_request(
formatted_url, params, access_token, time_range, resumable_source_manager
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/schemas.py b/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/schemas.py
index 2fbc10b72589..92e0f6efdd34 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/schemas.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/schemas.py
@@ -21,17 +21,39 @@ class MetaAdsResource(StrEnum):
CampaignStatsByRegion = "campaign_stats_by_region"
CampaignStatsByPlatform = "campaign_stats_by_platform"
CampaignStatsHourly = "campaign_stats_hourly"
+ AdsetStatsByAgeGender = "adset_stats_by_age_gender"
+ AdsetStatsByCountry = "adset_stats_by_country"
+ AdsetStatsByRegion = "adset_stats_by_region"
+ AdsetStatsByPlatform = "adset_stats_by_platform"
+ AdsetStatsHourly = "adset_stats_hourly"
+ AdStatsByAgeGender = "ad_stats_by_age_gender"
+ AdStatsByCountry = "ad_stats_by_country"
+ AdStatsByRegion = "ad_stats_by_region"
+ AdStatsByPlatform = "ad_stats_by_platform"
+ AdStatsHourly = "ad_stats_hourly"
# Insights broken down by a dimension. Each one multiplies the daily row count by the
# cardinality of its breakdown, and only some accounts care about any given dimension, so
-# they stay off in the schema picker until a user asks for them.
+# they stay off in the schema picker until a user asks for them. The same breakdown dimensions
+# are offered at campaign, adset and ad grain — creative testing and ad-fatigue analysis only
+# make sense at ad level, which campaign-grain rows can't express.
BREAKDOWN_STATS_ENDPOINTS = (
MetaAdsResource.CampaignStatsByAgeGender,
MetaAdsResource.CampaignStatsByCountry,
MetaAdsResource.CampaignStatsByRegion,
MetaAdsResource.CampaignStatsByPlatform,
MetaAdsResource.CampaignStatsHourly,
+ MetaAdsResource.AdsetStatsByAgeGender,
+ MetaAdsResource.AdsetStatsByCountry,
+ MetaAdsResource.AdsetStatsByRegion,
+ MetaAdsResource.AdsetStatsByPlatform,
+ MetaAdsResource.AdsetStatsHourly,
+ MetaAdsResource.AdStatsByAgeGender,
+ MetaAdsResource.AdStatsByCountry,
+ MetaAdsResource.AdStatsByRegion,
+ MetaAdsResource.AdStatsByPlatform,
+ MetaAdsResource.AdStatsHourly,
)
ENDPOINTS = (
@@ -74,12 +96,12 @@ INCREMENTAL_FIELDS: dict[str, list[IncrementalField]] = {
endpoint: _date_start_incremental_field() for endpoint in INCREMENTAL_ENDPOINTS
}
-# Insights metrics requested for every campaign-level breakdown table, mirroring `campaign_stats`.
-# Breakdown dimensions are deliberately absent: Meta returns them as columns automatically and
-# rejects the request when they are also passed in `fields`, since they are breakdowns rather
-# than AdsInsights fields.
-CAMPAIGN_BREAKDOWN_STATS_FIELDS = [
- "campaign_id",
+# Insights metrics requested for every breakdown table, at any level, mirroring the plain stats
+# tables. The grain columns (`ad_id`, `adset_id`, `campaign_id`) that identify a row are prepended
+# per level below. Breakdown dimensions are deliberately absent: Meta returns them as columns
+# automatically and rejects the request when they are also passed in `fields`, since they are
+# breakdowns rather than AdsInsights fields.
+_BREAKDOWN_METRIC_FIELDS = [
"account_id",
"account_currency",
"date_start",
@@ -96,37 +118,65 @@ CAMPAIGN_BREAKDOWN_STATS_FIELDS = [
"cost_per_unique_click",
"unique_clicks",
"unique_ctr",
+ "inline_link_clicks",
+ "outbound_clicks",
"actions",
+ "unique_actions",
"conversions",
"conversion_values",
"cost_per_action_type",
"action_values",
+ "purchase_roas",
+ "website_purchase_roas",
+ # The attribution window Meta actually applied to these rows, so imported numbers can be
+ # reconciled against Ads Manager (see the source's attribution-window config).
+ "attribution_setting",
]
+CAMPAIGN_BREAKDOWN_STATS_FIELDS = ["campaign_id", *_BREAKDOWN_METRIC_FIELDS]
+ADSET_BREAKDOWN_STATS_FIELDS = ["adset_id", "campaign_id", *_BREAKDOWN_METRIC_FIELDS]
+AD_BREAKDOWN_STATS_FIELDS = ["ad_id", "adset_id", "campaign_id", *_BREAKDOWN_METRIC_FIELDS]
+
# Meta: "Hourly breakdowns do not support unique fields, which are any fields prepended with
# `unique_*`, `reach` or `frequency`." `cpp` and `cost_per_unique_click` are derived from those,
# so the hourly table asks for none of them rather than storing columns Meta zeroes out.
-_HOURLY_UNSUPPORTED_FIELDS = {"reach", "frequency", "cpp", "cost_per_unique_click", "unique_clicks", "unique_ctr"}
+_HOURLY_UNSUPPORTED_FIELDS = {
+ "reach",
+ "frequency",
+ "cpp",
+ "cost_per_unique_click",
+ "unique_clicks",
+ "unique_ctr",
+ "unique_actions",
+}
+
-HOURLY_BREAKDOWN_STATS_FIELDS = [f for f in CAMPAIGN_BREAKDOWN_STATS_FIELDS if f not in _HOURLY_UNSUPPORTED_FIELDS]
+def _hourly_fields(field_names: list[str]) -> list[str]:
+ return [f for f in field_names if f not in _HOURLY_UNSUPPORTED_FIELDS]
-def _campaign_breakdown_stats(breakdowns: list[str], field_names: list[str] | None = None) -> dict[str, Any]:
- """Campaign-level Insights split by `breakdowns`.
+HOURLY_BREAKDOWN_STATS_FIELDS = _hourly_fields(CAMPAIGN_BREAKDOWN_STATS_FIELDS)
- Every breakdown dimension joins the primary key: a campaign/day pair now yields one row per
- combination of dimension values, so keying on `campaign_id + date_start` alone would collapse
+# The Insights `level` and its grain column, which heads that level's primary key and field list.
+_LEVEL_GRAIN_COLUMN = {"campaign": "campaign_id", "adset": "adset_id", "ad": "ad_id"}
+
+
+def _breakdown_stats(level: str, breakdowns: list[str], field_names: list[str]) -> dict[str, Any]:
+ """Insights split by `breakdowns` at `level` (campaign/adset/ad).
+
+ Every breakdown dimension joins the primary key: a grain/day pair now yields one row per
+ combination of dimension values, so keying on the grain id + `date_start` alone would collapse
them into duplicates that merge multi-matches on every sync.
"""
return {
- "primary_keys": ["campaign_id", "account_id", "date_start", *breakdowns],
+ "primary_keys": [_LEVEL_GRAIN_COLUMN[level], "account_id", "date_start", *breakdowns],
"url": "https://graph.facebook.com/{API_VERSION}/{account_id}/insights",
"extra_params": {
- "level": "campaign",
+ "level": level,
"time_increment": 1, # daily
"breakdowns": ",".join(breakdowns),
},
- "field_names": field_names if field_names is not None else CAMPAIGN_BREAKDOWN_STATS_FIELDS,
+ "field_names": field_names,
"partition_mode": "datetime",
"partition_format": "week",
"partition_keys": ["date_start"],
@@ -186,11 +236,17 @@ RESOURCE_SCHEMAS: dict[MetaAdsResource, dict[str, Any]] = {
"cost_per_unique_click",
"unique_clicks",
"unique_ctr",
+ "inline_link_clicks",
+ "outbound_clicks",
"actions",
+ "unique_actions",
"conversions",
"conversion_values",
"cost_per_action_type",
"action_values",
+ "purchase_roas",
+ "website_purchase_roas",
+ "attribution_setting",
"video_30_sec_watched_actions",
"video_p25_watched_actions",
"video_p50_watched_actions",
@@ -258,11 +314,17 @@ RESOURCE_SCHEMAS: dict[MetaAdsResource, dict[str, Any]] = {
"cost_per_unique_click",
"unique_clicks",
"unique_ctr",
+ "inline_link_clicks",
+ "outbound_clicks",
"actions",
+ "unique_actions",
"conversions",
"conversion_values",
"cost_per_action_type",
"action_values",
+ "purchase_roas",
+ "website_purchase_roas",
+ "attribution_setting",
],
"partition_mode": "datetime",
"partition_format": "week",
@@ -320,11 +382,17 @@ RESOURCE_SCHEMAS: dict[MetaAdsResource, dict[str, Any]] = {
"cost_per_unique_click",
"unique_clicks",
"unique_ctr",
+ "inline_link_clicks",
+ "outbound_clicks",
"actions",
+ "unique_actions",
"conversions",
"conversion_values",
"cost_per_action_type",
"action_values",
+ "purchase_roas",
+ "website_purchase_roas",
+ "attribution_setting",
],
"partition_mode": "datetime",
"partition_format": "week",
@@ -471,14 +539,33 @@ RESOURCE_SCHEMAS: dict[MetaAdsResource, dict[str, Any]] = {
"business",
],
},
- MetaAdsResource.CampaignStatsByAgeGender: _campaign_breakdown_stats(["age", "gender"]),
- MetaAdsResource.CampaignStatsByCountry: _campaign_breakdown_stats(["country"]),
- MetaAdsResource.CampaignStatsByRegion: _campaign_breakdown_stats(["region"]),
- MetaAdsResource.CampaignStatsByPlatform: _campaign_breakdown_stats(
- ["publisher_platform", "platform_position", "impression_device"]
+ MetaAdsResource.CampaignStatsByAgeGender: _breakdown_stats(
+ "campaign", ["age", "gender"], CAMPAIGN_BREAKDOWN_STATS_FIELDS
+ ),
+ MetaAdsResource.CampaignStatsByCountry: _breakdown_stats("campaign", ["country"], CAMPAIGN_BREAKDOWN_STATS_FIELDS),
+ MetaAdsResource.CampaignStatsByRegion: _breakdown_stats("campaign", ["region"], CAMPAIGN_BREAKDOWN_STATS_FIELDS),
+ MetaAdsResource.CampaignStatsByPlatform: _breakdown_stats(
+ "campaign", ["publisher_platform", "platform_position", "impression_device"], CAMPAIGN_BREAKDOWN_STATS_FIELDS
+ ),
+ MetaAdsResource.CampaignStatsHourly: _breakdown_stats(
+ "campaign", ["hourly_stats_aggregated_by_advertiser_time_zone"], HOURLY_BREAKDOWN_STATS_FIELDS
+ ),
+ MetaAdsResource.AdsetStatsByAgeGender: _breakdown_stats("adset", ["age", "gender"], ADSET_BREAKDOWN_STATS_FIELDS),
+ MetaAdsResource.AdsetStatsByCountry: _breakdown_stats("adset", ["country"], ADSET_BREAKDOWN_STATS_FIELDS),
+ MetaAdsResource.AdsetStatsByRegion: _breakdown_stats("adset", ["region"], ADSET_BREAKDOWN_STATS_FIELDS),
+ MetaAdsResource.AdsetStatsByPlatform: _breakdown_stats(
+ "adset", ["publisher_platform", "platform_position", "impression_device"], ADSET_BREAKDOWN_STATS_FIELDS
+ ),
+ MetaAdsResource.AdsetStatsHourly: _breakdown_stats(
+ "adset", ["hourly_stats_aggregated_by_advertiser_time_zone"], _hourly_fields(ADSET_BREAKDOWN_STATS_FIELDS)
+ ),
+ MetaAdsResource.AdStatsByAgeGender: _breakdown_stats("ad", ["age", "gender"], AD_BREAKDOWN_STATS_FIELDS),
+ MetaAdsResource.AdStatsByCountry: _breakdown_stats("ad", ["country"], AD_BREAKDOWN_STATS_FIELDS),
+ MetaAdsResource.AdStatsByRegion: _breakdown_stats("ad", ["region"], AD_BREAKDOWN_STATS_FIELDS),
+ MetaAdsResource.AdStatsByPlatform: _breakdown_stats(
+ "ad", ["publisher_platform", "platform_position", "impression_device"], AD_BREAKDOWN_STATS_FIELDS
),
- MetaAdsResource.CampaignStatsHourly: _campaign_breakdown_stats(
- ["hourly_stats_aggregated_by_advertiser_time_zone"],
- field_names=HOURLY_BREAKDOWN_STATS_FIELDS,
+ MetaAdsResource.AdStatsHourly: _breakdown_stats(
+ "ad", ["hourly_stats_aggregated_by_advertiser_time_zone"], _hourly_fields(AD_BREAKDOWN_STATS_FIELDS)
),
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/source.py
index 3637de559d66..f1bbce30a8a6 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/source.py
@@ -9,6 +9,8 @@ from posthog.schema import (
SourceFieldInputConfigType,
SourceFieldOauthAccountSelectConfig,
SourceFieldOauthConfig,
+ SourceFieldSelectConfig,
+ SourceFieldSelectConfigOption,
SuggestedTable,
)
@@ -222,6 +224,28 @@ class MetaAdsSource(ResumableSource[MetaAdsSourceConfig, MetaAdsResumeConfig], O
placeholder="90",
secret=False,
),
+ # Attribution settings for insights (spend/conversion) tables. Left unset, Meta
+ # applies its own default, so existing connections are unaffected. Set them to
+ # reconcile PostHog's numbers with Ads Manager, which reports on a specific window.
+ SourceFieldInputConfig(
+ name="action_attribution_windows",
+ label="Attribution windows for insights (comma-separated, e.g. 7d_click,1d_view)",
+ type=SourceFieldInputConfigType.TEXT,
+ required=False,
+ placeholder="7d_click,1d_view",
+ secret=False,
+ ),
+ SourceFieldSelectConfig(
+ name="use_unified_attribution_setting",
+ label="Use Meta's unified attribution setting",
+ required=False,
+ defaultValue="",
+ options=[
+ SourceFieldSelectConfigOption(label="Use Meta's default", value=""),
+ SourceFieldSelectConfigOption(label="Yes", value="true"),
+ SourceFieldSelectConfigOption(label="No", value="false"),
+ ],
+ ),
],
),
releaseStatus=ReleaseStatus.GA,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/test_meta_ads.py b/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/test_meta_ads.py
index 1ea30bded488..bb354814e751 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/test_meta_ads.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/test_meta_ads.py
@@ -1419,6 +1419,8 @@ class TestTimeRangeClamping:
config.account_id = "act_123"
config.meta_ads_integration_id = 1
config.sync_lookback_days = source_kwargs.pop("sync_lookback_days", None)
+ config.action_attribution_windows = None
+ config.use_unified_attribution_setting = None
response = meta_ads_source(
resource_name="campaign_stats",
@@ -1672,11 +1674,15 @@ class TestListAdAccounts:
assert call.kwargs["timeout"] == AD_ACCOUNT_LISTING_TIMEOUT_SECONDS
-def _source_config() -> mock.MagicMock:
+def _source_config(
+ *, action_attribution_windows: str | None = None, use_unified_attribution_setting: str | None = None
+) -> mock.MagicMock:
config = mock.MagicMock()
config.account_id = "act_123"
config.meta_ads_integration_id = 1
config.sync_lookback_days = None
+ config.action_attribution_windows = action_attribution_windows
+ config.use_unified_attribution_setting = use_unified_attribution_setting
return config
@@ -1704,6 +1710,24 @@ class TestBreakdownStatsSchemas:
# one key: duplicate rows seed the Delta table and each later merge multi-matches them.
assert set(breakdowns) <= set(schema.primary_keys)
+ @pytest.mark.parametrize(
+ "endpoint,level,grain_column",
+ [
+ (MetaAdsResource.CampaignStatsByCountry, "campaign", "campaign_id"),
+ (MetaAdsResource.AdsetStatsByCountry, "adset", "adset_id"),
+ (MetaAdsResource.AdStatsByCountry, "ad", "ad_id"),
+ ],
+ )
+ def test_level_sets_its_grain_column_as_key_and_field(self, endpoint: str, level: str, grain_column: str) -> None:
+ schema = get_meta_ads_schemas()[endpoint]
+
+ # The grain column is what makes an ad-level table distinct from the campaign-level one:
+ # keying an ad breakdown on `campaign_id` (or omitting `ad_id` from the request) would
+ # collapse every ad in a campaign onto one row and defeat the point of the finer grain.
+ assert schema.extra_params["level"] == level
+ assert grain_column in schema.primary_keys
+ assert grain_column in schema.field_names
+
@pytest.mark.parametrize("endpoint", list(BREAKDOWN_STATS_ENDPOINTS))
def test_breakdown_dimensions_are_not_requested_as_fields(self, endpoint: str) -> None:
schema = get_meta_ads_schemas()[endpoint]
@@ -1732,7 +1756,7 @@ class TestBreakdownStatsSchemas:
class TestBreakdownStatsRequests:
- def _capture_request(self, monkeypatch, resource_name: str) -> dict[str, Any]:
+ def _capture_request(self, monkeypatch, resource_name: str, config: mock.MagicMock | None = None) -> dict[str, Any]:
integration = mock.MagicMock()
integration.access_token = "token"
monkeypatch.setattr(meta_ads_module, "get_integration", lambda config, team_id: integration)
@@ -1747,7 +1771,7 @@ class TestBreakdownStatsRequests:
response = meta_ads_source(
resource_name=resource_name,
- config=_source_config(),
+ config=config or _source_config(),
team_id=1,
resumable_source_manager=_build_manager(),
)
@@ -1757,12 +1781,14 @@ class TestBreakdownStatsRequests:
@pytest.mark.parametrize("endpoint", list(BREAKDOWN_STATS_ENDPOINTS))
def test_breakdown_request_is_windowed_and_carries_its_breakdowns(self, monkeypatch, endpoint: str) -> None:
captured = self._capture_request(monkeypatch, endpoint)
+ schema = get_meta_ads_schemas()[endpoint]
# A breakdown table that loses `is_stats` would drop the time window and ask Meta for the
- # whole account history on every sync.
+ # whole account history on every sync. Each level (campaign/adset/ad) must send its own
+ # `level`, or ad-level breakdowns would silently return campaign-grain rows.
assert captured["time_range"] is not None
- assert captured["params"]["breakdowns"] == get_meta_ads_schemas()[endpoint].extra_params["breakdowns"]
- assert captured["params"]["level"] == "campaign"
+ assert captured["params"]["breakdowns"] == schema.extra_params["breakdowns"]
+ assert captured["params"]["level"] == schema.extra_params["level"]
def test_non_stats_endpoint_is_not_windowed(self, monkeypatch) -> None:
captured = self._capture_request(monkeypatch, MetaAdsResource.AdCreatives)
@@ -1770,6 +1796,40 @@ class TestBreakdownStatsRequests:
assert captured["time_range"] is None
assert captured["url"].endswith("/act_123/adcreatives")
+ def test_attribution_settings_omitted_when_unset(self, monkeypatch) -> None:
+ # Backward compatibility: an existing connection that never set attribution config must
+ # produce the same Insights request as before — Meta then applies its own default window.
+ captured = self._capture_request(monkeypatch, MetaAdsResource.CampaignStats)
+
+ assert "action_attribution_windows" not in captured["params"]
+ assert "use_unified_attribution_setting" not in captured["params"]
+
+ def test_attribution_settings_threaded_into_stats_request(self, monkeypatch) -> None:
+ config = _source_config(action_attribution_windows="7d_click, 1d_view", use_unified_attribution_setting="true")
+ captured = self._capture_request(monkeypatch, MetaAdsResource.CampaignStats, config)
+
+ # Windows are sent JSON-encoded (Meta's list-parameter shape) with surrounding whitespace
+ # trimmed; the unified-setting flag is passed through verbatim.
+ assert json.loads(captured["params"]["action_attribution_windows"]) == ["7d_click", "1d_view"]
+ assert captured["params"]["use_unified_attribution_setting"] == "true"
+
+ def test_attribution_default_sentinel_leaves_unified_setting_unset(self, monkeypatch) -> None:
+ # The "use Meta's default" picker option stores an empty string; it must not be sent as a
+ # value, or it would override Meta's default with a blank flag.
+ config = _source_config(use_unified_attribution_setting="")
+ captured = self._capture_request(monkeypatch, MetaAdsResource.CampaignStats, config)
+
+ assert "use_unified_attribution_setting" not in captured["params"]
+
+ def test_attribution_settings_not_sent_on_entity_endpoints(self, monkeypatch) -> None:
+ # Entity endpoints (campaigns, ads, ...) aren't Insights calls; Meta rejects attribution
+ # params there, so they must only ride on `is_stats` requests.
+ config = _source_config(action_attribution_windows="7d_click", use_unified_attribution_setting="true")
+ captured = self._capture_request(monkeypatch, MetaAdsResource.AdCreatives, config)
+
+ assert "action_attribution_windows" not in captured["params"]
+ assert "use_unified_attribution_setting" not in captured["params"]
+
class TestSingleObjectEndpoint:
"""`GET /act_<id>` returns the account node itself, not a paged `data` list."""