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.

fix(data-warehouse): stop google ads keyword and landing page syncs failing (#114311)

Luke Belton6f447edc1def
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/canonical_descriptions.py
index 2f00a1d52143..e5513556f1f3 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/canonical_descriptions.py
@@ -227,8 +227,6 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"docs_url": "https://developers.google.com/google-ads/api/fields/v17/keyword_view",
"columns": _stats_columns(
ad_group_criterion_criterion_id="Unique ID of the keyword criterion the metrics belong to.",
- metrics_top_impression_percentage="Fraction of Google Search ad impressions shown among the top ads.",
- metrics_absolute_top_impression_percentage="Fraction of Google Search ad impressions shown as the first ad.",
),
},
"video": {
@@ -561,8 +559,6 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"columns": _stats_columns(
**{
"landing_page_view_unexpanded_final_url": "The final URL as entered by the advertiser, before URL expansion.",
- "metrics_top_impression_percentage": "Fraction of Google Search ad impressions shown among the top ads.",
- "metrics_absolute_top_impression_percentage": "Fraction of Google Search ad impressions shown as the first ad.",
"metrics_speed_score": "Google's 0-100 estimate of how fast the landing page loads on mobile, relative to other pages.",
"metrics_mobile_friendly_clicks_percentage": "Percentage of mobile clicks that went to a mobile-friendly page.",
"metrics_valid_accelerated_mobile_pages_clicks_percentage": "Percentage of clicks to a landing page that is a valid AMP page.",
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/schemas.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/schemas.py
index d83ee71718ab..dfe0699e3a7d 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/schemas.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/schemas.py
@@ -587,8 +587,6 @@ RESOURCE_SCHEMAS: dict[str, dict[str, Any]] = {
"metrics.gmail_saves",
"metrics.gmail_secondary_clicks",
"metrics.impressions",
- "metrics.top_impression_percentage",
- "metrics.absolute_top_impression_percentage",
"metrics.interaction_event_types",
"metrics.interaction_rate",
"metrics.interactions",
@@ -1245,8 +1243,6 @@ RESOURCE_SCHEMAS: dict[str, dict[str, Any]] = {
"customer.currency_code",
"metrics.clicks",
"metrics.impressions",
- "metrics.top_impression_percentage",
- "metrics.absolute_top_impression_percentage",
"metrics.cost_micros",
"metrics.conversions",
"metrics.conversions_value",
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/tests/test_google_ads_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/tests/test_google_ads_source.py
index 11e5719e4e42..de592e6abac5 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/tests/test_google_ads_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/tests/test_google_ads_source.py
@@ -2075,6 +2075,67 @@ class TestResourceSchemaInvariants:
assert contents["filter_field_names"] == [("segments.date", IncrementalFieldType.Date)]
assert "segments.date" in contents["field_names"]
+ @pytest.mark.parametrize("alias", sorted(RESOURCE_SCHEMAS))
+ def test_top_impression_metrics_use_a_compatible_resource_and_segments(self, alias):
+ # Google rejects the whole query when these metrics meet a resource or segment outside their
+ # "Selectable with" list, so every sync of the table fails.
+ contents = RESOURCE_SCHEMAS[alias]
+ if not _TOP_IMPRESSION_METRICS & set(contents["field_names"]):
+ return
+ assert contents["resource_name"] in _TOP_IMPRESSION_SELECTABLE_RESOURCES
+ segments = {field for field in contents["field_names"] if field.startswith("segments.")}
+ assert segments <= _TOP_IMPRESSION_SELECTABLE_SEGMENTS
+
+
+_TOP_IMPRESSION_METRICS = {"metrics.top_impression_percentage", "metrics.absolute_top_impression_percentage"}
+
+# The "Selectable with" list that both metrics share in the Google Ads API v25 metrics reference:
+# https://developers.google.com/google-ads/api/fields/v25/metrics#metrics.top_impression_percentage
+_TOP_IMPRESSION_SELECTABLE_RESOURCES = {
+ "ad_group",
+ "ad_group_ad",
+ "ad_group_asset",
+ "ad_group_audience_view",
+ "asset_set_asset",
+ "campaign",
+ "campaign_asset",
+ "campaign_audience_view",
+ "campaign_search_term_view",
+ "customer",
+ "customer_asset",
+ "geographic_view",
+ "keyword_view",
+ "location_interest_view",
+ "search_term_view",
+ "targeting_expansion_view",
+ "webpage_view",
+}
+_TOP_IMPRESSION_SELECTABLE_SEGMENTS = {
+ "segments.ad_network_type",
+ "segments.ad_sub_network_type",
+ "segments.asset_interaction_target.asset",
+ "segments.asset_interaction_target.interaction_on_this_asset",
+ "segments.date",
+ "segments.day_of_week",
+ "segments.device",
+ "segments.geo_target_city",
+ "segments.geo_target_country",
+ "segments.geo_target_metro",
+ "segments.geo_target_region",
+ "segments.hour",
+ "segments.keyword.ad_group_criterion",
+ "segments.keyword.info.match_type",
+ "segments.keyword.info.text",
+ "segments.match_type",
+ "segments.month",
+ "segments.quarter",
+ "segments.search_term_match_source",
+ "segments.search_term_match_type",
+ "segments.search_term_targeting_status",
+ "segments.week",
+ "segments.year",
+}
+
class TestConversionActionSegmentedStats:
@pytest.mark.parametrize(