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(google_ads): add ad and ad_group overview stats tables (#66463)

Daniel RC8dd6bbbd5112
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 4f6b30e08e57..d1621cc5d013 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
@@ -60,6 +60,12 @@ def _stats_columns(**overrides: str) -> dict[str, str]:
return {**_IDS, **_METRICS, **_SEGMENTS, **overrides}
+def _overview_stats_columns(**overrides: str) -> dict[str, str]:
+ """Like _stats_columns but without segments_click_type — overview tables don't segment by click type."""
+ segments = {k: v for k, v in _SEGMENTS.items() if k != "segments_click_type"}
+ return {**_IDS, **_METRICS, **segments, **overrides}
+
+
CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"ad": {
"description": "An ad within an ad group (ad_group_ad), including its creative content and status.",
@@ -84,6 +90,14 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
metrics_active_view_measurability="Share of impressions that were measurable by Active View.",
),
},
+ "ad_overview_stats": {
+ "description": "Daily ad (ad_group_ad) performance without click-type segmentation, so cost totals reconcile to the Google Ads UI. Segmented by date, device, and network.",
+ "docs_url": "https://developers.google.com/google-ads/api/fields/v17/ad_group_ad",
+ "columns": _overview_stats_columns(
+ ad_group_ad_ad_id="Unique ID of the ad the metrics belong to.",
+ metrics_active_view_measurability="Share of impressions that were measurable by Active View.",
+ ),
+ },
"ad_group": {
"description": "An ad group — a set of ads and keywords sharing bids and targeting within a campaign.",
"docs_url": "https://developers.google.com/google-ads/api/fields/v17/ad_group",
@@ -103,6 +117,11 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"docs_url": "https://developers.google.com/google-ads/api/fields/v17/ad_group",
"columns": _stats_columns(),
},
+ "ad_group_overview_stats": {
+ "description": "Daily ad group performance without click-type segmentation, so cost totals reconcile to the Google Ads UI. Segmented by date, device, and network.",
+ "docs_url": "https://developers.google.com/google-ads/api/fields/v17/ad_group",
+ "columns": _overview_stats_columns(),
+ },
"campaign": {
"description": "A Google Ads campaign — a budgeted set of ad groups sharing settings and goals.",
"docs_url": "https://developers.google.com/google-ads/api/fields/v17/campaign",
@@ -131,7 +150,7 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"campaign_overview_stats": {
"description": "Daily campaign performance overview including video metrics, segmented by date and device.",
"docs_url": "https://developers.google.com/google-ads/api/fields/v17/campaign",
- "columns": _stats_columns(
+ "columns": _overview_stats_columns(
campaign_name="Name of the campaign.",
campaign_advertising_channel_type="Primary serving target of the campaign.",
metrics_video_views="Number of views of a video ad.",
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 beca3050ef8c..733b81c57ba6 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
@@ -1,3 +1,5 @@
+from typing import Any
+
from products.warehouse_sources.backend.types import IncrementalFieldType
FIELD_ALIASES: dict[str, str] = {
@@ -8,7 +10,7 @@ FIELD_ALIASES: dict[str, str] = {
"campaign.end_date_time": "campaign.end_date",
}
-RESOURCE_SCHEMAS = {
+RESOURCE_SCHEMAS: dict[str, dict[str, Any]] = {
"ad": {
"resource_name": "ad_group_ad",
"primary_key": ["ad_group_ad.ad.id", "ad_group.id", "campaign.id", "customer.id"],
@@ -152,6 +154,65 @@ RESOURCE_SCHEMAS = {
"segments.year",
],
},
+ "ad_overview_stats": {
+ "resource_name": "ad_group_ad",
+ "primary_key": [
+ "ad_group_ad.ad.id",
+ "ad_group.id",
+ "campaign.id",
+ "customer.id",
+ "segments.ad_network_type",
+ "segments.date",
+ "segments.device",
+ ],
+ "filter_field_names": [("segments.date", IncrementalFieldType.Date)],
+ "field_names": [
+ "ad_group_ad.ad.id",
+ "ad_group.id",
+ "campaign.id",
+ "customer.id",
+ "customer.currency_code",
+ "ad_group_ad.ad_group",
+ "ad_group.base_ad_group",
+ "campaign.base_campaign",
+ "metrics.active_view_cpm",
+ "metrics.active_view_ctr",
+ "metrics.active_view_impressions",
+ "metrics.active_view_measurability",
+ "metrics.active_view_measurable_cost_micros",
+ "metrics.active_view_measurable_impressions",
+ "metrics.active_view_viewability",
+ "metrics.average_cost",
+ "metrics.average_cpc",
+ "metrics.average_cpm",
+ "metrics.clicks",
+ "metrics.conversions",
+ "metrics.conversions_from_interactions_rate",
+ "metrics.conversions_value",
+ "metrics.cost_micros",
+ "metrics.cost_per_conversion",
+ "metrics.cost_per_current_model_attributed_conversion",
+ "metrics.ctr",
+ "metrics.current_model_attributed_conversions",
+ "metrics.gmail_forwards",
+ "metrics.gmail_saves",
+ "metrics.gmail_secondary_clicks",
+ "metrics.impressions",
+ "metrics.interaction_event_types",
+ "metrics.interaction_rate",
+ "metrics.interactions",
+ "metrics.value_per_conversion",
+ "metrics.value_per_current_model_attributed_conversion",
+ "segments.ad_network_type",
+ "segments.date",
+ "segments.day_of_week",
+ "segments.device",
+ "segments.month",
+ "segments.quarter",
+ "segments.week",
+ "segments.year",
+ ],
+ },
"ad_group": {
"resource_name": "ad_group",
"primary_key": ["ad_group.id", "campaign.id", "customer.id"],
@@ -238,6 +299,63 @@ RESOURCE_SCHEMAS = {
"segments.year",
],
},
+ "ad_group_overview_stats": {
+ "resource_name": "ad_group",
+ "filter_field_names": [("segments.date", IncrementalFieldType.Date)],
+ "primary_key": [
+ "ad_group.id",
+ "campaign.id",
+ "customer.id",
+ "segments.ad_network_type",
+ "segments.date",
+ "segments.device",
+ ],
+ "field_names": [
+ "ad_group.id",
+ "campaign.id",
+ "customer.id",
+ "customer.currency_code",
+ "ad_group.base_ad_group",
+ "campaign.base_campaign",
+ "metrics.active_view_cpm",
+ "metrics.active_view_ctr",
+ "metrics.active_view_impressions",
+ "metrics.active_view_measurability",
+ "metrics.active_view_measurable_cost_micros",
+ "metrics.active_view_measurable_impressions",
+ "metrics.active_view_viewability",
+ "metrics.average_cost",
+ "metrics.average_cpc",
+ "metrics.average_cpm",
+ "metrics.clicks",
+ "metrics.conversions",
+ "metrics.conversions_from_interactions_rate",
+ "metrics.conversions_value",
+ "metrics.cost_micros",
+ "metrics.cost_per_conversion",
+ "metrics.cost_per_current_model_attributed_conversion",
+ "metrics.ctr",
+ "metrics.current_model_attributed_conversions",
+ "metrics.current_model_attributed_conversions_value",
+ "metrics.gmail_forwards",
+ "metrics.gmail_saves",
+ "metrics.gmail_secondary_clicks",
+ "metrics.impressions",
+ "metrics.interaction_event_types",
+ "metrics.interaction_rate",
+ "metrics.interactions",
+ "metrics.value_per_conversion",
+ "metrics.value_per_current_model_attributed_conversion",
+ "segments.ad_network_type",
+ "segments.date",
+ "segments.day_of_week",
+ "segments.device",
+ "segments.month",
+ "segments.quarter",
+ "segments.week",
+ "segments.year",
+ ],
+ },
"campaign": {
"resource_name": "campaign",
"primary_key": ["campaign.id", "customer.id"],
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 6c504712290a..565f7d8ef6e0 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
@@ -29,7 +29,9 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.google_ads
_load_client_with_transient_retry,
_search_as_arrow_tables,
)
+from products.warehouse_sources.backend.temporal.data_imports.sources.google_ads.schemas import RESOURCE_SCHEMAS
from products.warehouse_sources.backend.temporal.data_imports.sources.google_ads.source import GoogleAdsSource
+from products.warehouse_sources.backend.types import IncrementalFieldType
_CUSTOMER_ID_ERROR = "valid Google Ads customer ID"
_MANAGER_ID_ERROR = "valid Google Ads manager customer ID"
@@ -738,3 +740,27 @@ class TestGetIntegrationDbResilience:
assert result is integration
assert get.call_count == 1
assert close.call_count == 1
+
+
+class TestOverviewStatsSchemas:
+ # Overview stats tables exist to recover cost that click-type segmentation drops: requesting
+ # segments.click_type makes Google omit cost not yet attributed to a click type, so summed cost
+ # reads low for recent days. Each overview must equal its *_stats counterpart minus that one
+ # segment, while staying incremental on segments.date.
+ @pytest.mark.parametrize(
+ "overview_alias, stats_alias",
+ [
+ ("ad_overview_stats", "ad_stats"),
+ ("ad_group_overview_stats", "ad_group_stats"),
+ ],
+ )
+ def test_overview_equals_stats_table_without_click_type(self, overview_alias, stats_alias):
+ overview = RESOURCE_SCHEMAS[overview_alias]
+ stats = RESOURCE_SCHEMAS[stats_alias]
+
+ assert "segments.click_type" not in overview["field_names"]
+ assert "segments.click_type" not in overview["primary_key"]
+ assert overview["resource_name"] == stats["resource_name"]
+ assert overview["field_names"] == [f for f in stats["field_names"] if f != "segments.click_type"]
+ assert overview["primary_key"] == [k for k in stats["primary_key"] if k != "segments.click_type"]
+ assert overview["filter_field_names"] == [("segments.date", IncrementalFieldType.Date)]