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(warehouse-sources): support Google Ads API v24 (#71684)

Tom Owers46b2ce4d0da2
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/google_ads.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/google_ads.py
index d550cf62d8d3..0adef058e798 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/google_ads.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/google_ads.py
@@ -21,6 +21,9 @@ from google.ads.googleads.v23.services.services.google_ads_field_service import
pagers as field_service_pagers,
)
from google.ads.googleads.v23.services.services.google_ads_service import GoogleAdsServiceClient, pagers
+from google.ads.googleads.v24.common import types as ga_common_v24
+from google.ads.googleads.v24.enums import types as ga_enums_v24
+from google.ads.googleads.v24.resources import types as ga_resources_v24
from google.api_core import exceptions as google_api_exceptions
from google.auth import exceptions as google_auth_exceptions
from google.oauth2 import service_account
@@ -308,39 +311,36 @@ class GoogleAdsColumn(Column):
return pa.field(self.name, arrow_type)
+# Per-version proto module sets used to resolve a search response's type URLs back to their Python
+# classes. A response's type URL carries the API version it was produced under, so we decode enums
+# and messages against the matching version's modules. Enum *data-type* constants used elsewhere
+# (`GoogleAdsColumn`) are stable across versions and keep using the v23 modules.
+_PROTO_MODULES_BY_VERSION: dict[str, dict[str, typing.Any]] = {
+ "v23": {"common": ga_common, "enums": ga_enums, "resources": ga_resources},
+ "v24": {"common": ga_common_v24, "enums": ga_enums_v24, "resources": ga_resources_v24},
+}
+
+
def _resolve_protobuf_message_type_url(type_url: str) -> type:
- """Traverse a protobuf message type URL to find it's Python type."""
+ """Traverse a protobuf message type URL to find it's Python type.
+
+ The version segment of the URL selects the matching SDK module set, so a response produced
+ under any supported API version resolves against that version's protos.
+ """
match type_url.split("."):
- case ["google", "ads", "googleads", "v23", "common", *rest] | [
- "com",
- "google",
- "ads",
- "googleads",
- "v23",
- "common",
- *rest,
- ]:
- return _traverse_attributes(ga_common, *rest)
- case ["google", "ads", "googleads", "v23", "enums", *rest] | [
+ case ["google", "ads", "googleads", version, category, *rest] | [
"com",
"google",
"ads",
"googleads",
- "v23",
- "enums",
+ version,
+ category,
*rest,
]:
- return _traverse_attributes(ga_enums, *rest)
- case ["google", "ads", "googleads", "v23", "resources", *rest] | [
- "com",
- "google",
- "ads",
- "googleads",
- "v23",
- "resources",
- *rest,
- ]:
- return _traverse_attributes(ga_resources, *rest)
+ module = _PROTO_MODULES_BY_VERSION.get(version, {}).get(category)
+ if module is not None:
+ return _traverse_attributes(module, *rest)
+ raise ValueError(f"Type url could not be found: '{type_url}'")
case _:
raise ValueError(f"Type url could not be found: '{type_url}'")
@@ -394,7 +394,7 @@ class GoogleAdsTable(Table[GoogleAdsColumn]):
TableSchemas = dict[str, GoogleAdsTable]
-def get_schemas(config: GoogleAdsSourceConfigUnion, team_id: int) -> TableSchemas:
+def get_schemas(config: GoogleAdsSourceConfigUnion, team_id: int, api_version: str) -> TableSchemas:
"""Obtain Google Ads schemas.
This is a two step process:
@@ -404,7 +404,9 @@ def get_schemas(config: GoogleAdsSourceConfigUnion, team_id: int) -> TableSchema
Only selectable fields are, well, selected.
"""
client = google_ads_client(config, team_id)
- gaf_service = client.get_service("GoogleAdsFieldService", interceptors=tracked_interceptors(GOOGLE_ADS_HOST))
+ gaf_service = client.get_service(
+ "GoogleAdsFieldService", version=api_version, interceptors=tracked_interceptors(GOOGLE_ADS_HOST)
+ )
fields_query = _search_fields_with_transient_retry(
gaf_service, "select name, data_type, is_repeated, type_url where selectable = true"
)
@@ -485,6 +487,7 @@ def google_ads_source(
resource_name: str,
team_id: int,
resumable_source_manager: ResumableSourceManager[GoogleAdsResumeConfig],
+ api_version: str,
should_use_incremental_field: bool = False,
db_incremental_field_last_value: typing.Any = None,
incremental_field: str | None = None,
@@ -501,7 +504,7 @@ def google_ads_source(
"""
name = NamingConvention.normalize_identifier(resource_name)
- table = get_schemas(config, team_id)[resource_name]
+ table = get_schemas(config, team_id, api_version)[resource_name]
if table.requires_filter and not should_use_incremental_field:
should_use_incremental_field = True
@@ -538,7 +541,7 @@ def google_ads_source(
def get_rows() -> collections.abc.Iterator[pa.Table]:
client = google_ads_client(config, team_id)
service: GoogleAdsServiceClient = client.get_service(
- "GoogleAdsService", version="v23", interceptors=tracked_interceptors(GOOGLE_ADS_HOST)
+ "GoogleAdsService", version=api_version, interceptors=tracked_interceptors(GOOGLE_ADS_HOST)
)
customer_id = clean_customer_id(config.customer_id)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/source.py
index 15460062d6c2..ba8134e5bd4a 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/source.py
@@ -82,8 +82,8 @@ def _oauth_accounts_cache_key(team_id: int, integration_id: int) -> str:
class GoogleAdsSource(
ResumableSource[GoogleAdsSourceConfig | GoogleAdsServiceAccountSourceConfig, GoogleAdsResumeConfig], OAuthMixin
):
- supported_versions = ("v23",)
- default_version = "v23"
+ supported_versions = ("v23", "v24")
+ default_version = "v24"
api_docs_url = "https://developers.google.com/google-ads/api/docs/release-notes"
@property
@@ -151,9 +151,12 @@ class GoogleAdsSource(
get_schemas as get_google_ads_schemas,
)
+ # Discover against the source's pinned version (falling back to the default) so a
+ # v23-pinned source reconciles schemas under v23, matching its sync path — not v24.
google_ads_schemas = get_google_ads_schemas(
config,
team_id,
+ self.resolve_api_version(api_version),
)
ads_incremental_fields = get_google_ads_incremental_fields()
@@ -204,6 +207,7 @@ class GoogleAdsSource(
resource_name=inputs.schema_name,
team_id=inputs.team_id,
resumable_source_manager=resumable_source_manager,
+ api_version=self.resolve_api_version(inputs.api_version),
should_use_incremental_field=inputs.should_use_incremental_field,
incremental_field=inputs.incremental_field if inputs.should_use_incremental_field else None,
incremental_field_type=inputs.incremental_field_type if inputs.should_use_incremental_field else None,
@@ -365,7 +369,9 @@ class GoogleAdsSource(
return is_valid, errors
- def _validate_mcc_customer_access(self, client, config: GoogleAdsSourceConfig) -> tuple[bool, str | None]:
+ def _validate_mcc_customer_access(
+ self, client, config: GoogleAdsSourceConfig, api_version: str
+ ) -> tuple[bool, str | None]:
"""Validate that a client account is accessible through a manager (MCC) account.
list_accessible_customers() only returns manager-level accounts, not client accounts
@@ -373,7 +379,7 @@ class GoogleAdsSource(
is configured correctly in the client, this will succeed.
"""
cleaned_customer_id = clean_customer_id(config.customer_id)
- ga_service = client.get_service("GoogleAdsService")
+ ga_service = client.get_service("GoogleAdsService", version=api_version)
query = "SELECT customer.id FROM customer"
try:
response = ga_service.search(customer_id=cleaned_customer_id, query=query)
@@ -400,13 +406,17 @@ class GoogleAdsSource(
google_ads_client,
)
+ # The SDK's client default is the newest bundled version, so leaving these probes unpinned
+ # would validate against a version the source may not sync with.
+ resolved_version = self.resolve_api_version(api_version)
+
try:
client = google_ads_client(config, team_id)
if isinstance(config, GoogleAdsSourceConfig) and config.is_mcc_account and config.is_mcc_account.enabled:
- return self._validate_mcc_customer_access(client, config)
+ return self._validate_mcc_customer_access(client, config, resolved_version)
- customer_service = client.get_service("CustomerService")
+ customer_service = client.get_service("CustomerService", version=resolved_version)
accessible_customers = customer_service.list_accessible_customers()
customer_resource_name = f"customers/{clean_customer_id(config.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 c9151efc1a7b..b48460ce3df3 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
@@ -25,6 +25,7 @@ from posthog.schema import SourceFieldOauthConfig
from posthog.models.integration import Integration
from products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.googleads import (
+ GoogleAdsIsMccAccountConfig,
GoogleAdsSourceConfig,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.google_ads.configs import (
@@ -42,8 +43,11 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.google_ads
_is_transient_client_init_error,
_is_transient_grpc_error,
_load_client_with_transient_retry,
+ _resolve_protobuf_message_type_url,
_search_as_arrow_tables,
_search_fields_with_transient_retry,
+ get_schemas,
+ google_ads_source,
)
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
@@ -1195,7 +1199,14 @@ class TestGoogleAdsQueryConstruction:
description=None,
)
- def _run_source(self, table: GoogleAdsTable, *, window_rows: dict[str, int] | None = None, **source_kwargs):
+ def _run_source(
+ self,
+ table: GoogleAdsTable,
+ *,
+ api_version: str = "v23",
+ window_rows: dict[str, int] | None = None,
+ **source_kwargs,
+ ):
from products.warehouse_sources.backend.temporal.data_imports.sources.google_ads.google_ads import (
google_ads_source,
)
@@ -1226,6 +1237,7 @@ class TestGoogleAdsQueryConstruction:
table.alias,
team_id=1,
resumable_source_manager=mock.Mock(),
+ api_version=api_version,
**source_kwargs,
)
list(typing.cast(collections.abc.Iterable, response.items()))
@@ -1318,3 +1330,114 @@ class TestGoogleAdsQueryConstruction:
assert "WHERE" not in queries[0]
assert "ORDER BY" not in queries[0]
+
+
+_GOOGLE_ADS_MODULE = "products.warehouse_sources.backend.temporal.data_imports.sources.google_ads.google_ads"
+
+
+class TestVersionDeclaration:
+ def test_v24_is_default_and_both_versions_supported(self):
+ source = GoogleAdsSource()
+ assert source.default_version == "v24"
+ assert set(source.supported_versions) == {"v23", "v24"}
+
+ @pytest.mark.parametrize(
+ "pin, expected",
+ [("v23", "v23"), ("v24", "v24"), (None, "v24"), ("", "v24")],
+ )
+ def test_resolve_api_version_honors_pin_and_defaults_to_v24(self, pin, expected):
+ # A present pin is honored verbatim so an existing v23 source is never silently moved; an
+ # empty/missing pin falls back to the new v24 default that new sources are stamped with.
+ assert GoogleAdsSource().resolve_api_version(pin) == expected
+
+
+class TestApiVersionDispatch:
+ @pytest.mark.parametrize("api_version", ["v23", "v24"])
+ def test_search_service_built_for_resolved_version(self, api_version):
+ # The resolved pin must reach GoogleAdsService.get_service so each source syncs against the
+ # version it is pinned to — the SDK's default flipped to the newest version, so an unpinned
+ # call would silently move v23 sources to v24.
+ client = mock.Mock()
+ table = _single_row_table()
+ assert table.alias is not None
+ config = GoogleAdsSourceConfig(customer_id="1234567890", google_ads_integration_id=1)
+ with (
+ mock.patch(f"{_GOOGLE_ADS_MODULE}.get_schemas", return_value={table.alias: table}),
+ mock.patch(f"{_GOOGLE_ADS_MODULE}.google_ads_client", return_value=client),
+ mock.patch(f"{_GOOGLE_ADS_MODULE}._search_as_arrow_tables", return_value=iter([])),
+ ):
+ response = google_ads_source(
+ config,
+ table.alias,
+ team_id=1,
+ resumable_source_manager=mock.Mock(),
+ api_version=api_version,
+ )
+ list(typing.cast(collections.abc.Iterable, response.items()))
+
+ client.get_service.assert_called_once_with("GoogleAdsService", version=api_version, interceptors=mock.ANY)
+
+ @pytest.mark.parametrize("api_version", ["v23", "v24"])
+ def test_field_service_built_for_resolved_version(self, api_version):
+ # Schema discovery must also target the resolved version — before the SDK bump it relied on
+ # the client default being v23, which the bump changed to the newest version.
+ client = mock.Mock()
+ config = GoogleAdsSourceConfig(customer_id="1234567890", google_ads_integration_id=1)
+ with (
+ mock.patch(f"{_GOOGLE_ADS_MODULE}.google_ads_client", return_value=client),
+ mock.patch(
+ f"{_GOOGLE_ADS_MODULE}._search_fields_with_transient_retry",
+ return_value=SimpleNamespace(results=[]),
+ ),
+ mock.patch(f"{_GOOGLE_ADS_MODULE}.RESOURCE_SCHEMAS", {}),
+ ):
+ get_schemas(config, team_id=1, api_version=api_version)
+
+ client.get_service.assert_called_once_with("GoogleAdsFieldService", version=api_version, interceptors=mock.ANY)
+
+ @pytest.mark.parametrize(
+ "is_mcc, service_name",
+ [(False, "CustomerService"), (True, "GoogleAdsService")],
+ ids=["direct_account_probe", "mcc_account_probe"],
+ )
+ @pytest.mark.parametrize("pin, expected", [("v23", "v23"), (None, "v24")])
+ def test_validate_credentials_probes_are_pinned(self, is_mcc, service_name, pin, expected):
+ # Unpinned probes fall through to the SDK's newest bundled version, so a v23 source would
+ # be validated against v24 and pass (or fail) on a version it never syncs with.
+ client = mock.Mock()
+ config = GoogleAdsSourceConfig(
+ customer_id="1234567890",
+ google_ads_integration_id=1,
+ is_mcc_account=GoogleAdsIsMccAccountConfig(mcc_client_id="9876543210", enabled=True) if is_mcc else None,
+ )
+ with mock.patch(f"{_GOOGLE_ADS_MODULE}.google_ads_client", return_value=client):
+ GoogleAdsSource().validate_credentials(config, team_id=1, api_version=pin)
+
+ client.get_service.assert_called_once_with(service_name, version=expected)
+
+
+class TestDiscoveryVersionThreading:
+ _SCHEMAS_PATH = "products.warehouse_sources.backend.temporal.data_imports.sources.google_ads.google_ads.get_schemas"
+
+ @pytest.mark.parametrize("pin, expected", [("v23", "v23"), ("v24", "v24"), (None, "v24")])
+ def test_get_schemas_discovers_against_resolved_pin(self, pin, expected):
+ # Discovery must reconcile against the source's pinned version, not always the default —
+ # a v23-pinned source must not discover schemas under the newer default (v24).
+ config = GoogleAdsSourceConfig(customer_id="1234567890", google_ads_integration_id=1)
+ with mock.patch(self._SCHEMAS_PATH, return_value={}) as mock_get_schemas:
+ GoogleAdsSource().get_schemas(config, team_id=1, api_version=pin)
+
+ mock_get_schemas.assert_called_once_with(config, 1, expected)
+
+
+class TestTypeUrlVersionResolution:
+ @pytest.mark.parametrize("api_version", ["v23", "v24"])
+ def test_resolves_enum_type_url_against_matching_version(self, api_version):
+ # Response type URLs carry the API version they were produced under, so the resolver must
+ # decode a v23 and a v24 response each against its own protos.
+ enum_cls = _resolve_protobuf_message_type_url(f"google.ads.googleads.{api_version}.enums.DeviceEnum")
+ assert enum_cls.__module__.startswith(f"google.ads.googleads.{api_version}.")
+
+ def test_unknown_version_raises(self):
+ with pytest.raises(ValueError):
+ _resolve_protobuf_message_type_url("google.ads.googleads.v99.enums.DeviceEnum")
diff --git a/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/test_google_ads_source.py b/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/test_google_ads_source.py
index 821c49fbe0c2..b6390102e4a3 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/test_google_ads_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/test_google_ads_source.py
@@ -147,7 +147,7 @@ def test_get_schemas(customer_id: str, developer_token: str, service_account_con
cfg = GoogleAdsServiceAccountSourceConfig(
customer_id=customer_id, developer_token=developer_token, **service_account_config
)
- schemas = get_schemas(cfg, team_id=team.id)
+ schemas = get_schemas(cfg, team_id=team.id, api_version=GoogleAdsSource().default_version)
assert "campaign" in schemas
assert "ad_group" in schemas
@@ -214,6 +214,7 @@ def test_google_ads_source(customer_id: str, developer_token: str, service_accou
resource_name=resource,
team_id=team.id,
resumable_source_manager=manager,
+ api_version=GoogleAdsSource().default_version,
)
items = source.items()
diff --git a/pyproject.toml b/pyproject.toml
index 14a8a84ede7a..07db233ab128 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -58,7 +58,7 @@ dependencies = [
"drf-extensions~=0.8.0",
"drf-spectacular~=0.29.0",
"geoip2==4.6.0",
- "google-ads==29.2.0",
+ "google-ads==30.1.0",
"google-cloud-bigquery==3.26",
"google-cloud-bigquery-storage==2.32.0",
"google-cloud-iam==2.21",
diff --git a/uv.lock b/uv.lock
index 383b3472cb23..4471a6c87ec1 100644
--- a/uv.lock
+++ b/uv.lock
@@ -2590,7 +2590,7 @@ wheels = [
[[package]]
name = "google-ads"
-version = "29.2.0"
+version = "30.1.0"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "google-api-core" },
@@ -2602,9 +2602,9 @@ dependencies = [
{ name = "protobuf" },
{ name = "pyyaml" },
]
-sdist = { url = "https://files.pythonhosted.org/packages/44/eb/92edcc232060fc3bdee6f3f147f986db844083b157794658e9bb6ff05cc9/google_ads-29.2.0.tar.gz", hash = "sha256:d2331f2a79447792f80ce2a17f46eebc4003d3e4228b2e580e20af313dce8ed0", size = 9628865, upload-time = "2026-02-25T21:37:44.799Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/f0/e0/7660c28100d5ef82d8e7348e2f38938c89547d80cd2984692cf7fcf2ee85/google_ads-30.1.0.tar.gz", hash = "sha256:beecd95690cbb5fff728d5455f67588f0af12aec1fb3c54ad373a5a57716e9f4", size = 12140520, upload-time = "2026-04-22T20:55:22.984Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/61/a3/4f3cef090c97dd307048b6e3075cdc45f913584c32c6a8d45de71ad31702/google_ads-29.2.0-py3-none-any.whl", hash = "sha256:264d98b5a08158702d91248be633e104436da522b2a513fc90f983e39553380d", size = 18308345, upload-time = "2026-02-25T21:37:41.956Z" },
+ { url = "https://files.pythonhosted.org/packages/2e/c6/d198458fb6fa09492f0ef066fcd64ab1f2e5188b369bcba278b4a686eb24/google_ads-30.1.0-py3-none-any.whl", hash = "sha256:ed58ecf23511009664a5628f6d615365459585d55d889a4ba5e98ee652fbef1b", size = 23076755, upload-time = "2026-04-22T20:55:18.936Z" },
]
[[package]]
@@ -5873,7 +5873,7 @@ requires-dist = [
{ name = "geoip2", specifier = "==4.6.0" },
{ name = "gitpython", specifier = "~=3.1.44" },
{ name = "glom", specifier = "~=24.11.0" },
- { name = "google-ads", specifier = "==29.2.0" },
+ { name = "google-ads", specifier = "==30.1.0" },
{ name = "google-cloud-bigquery", specifier = "==3.26" },
{ name = "google-cloud-bigquery-storage", specifier = "==2.32.0" },
{ name = "google-cloud-iam", specifier = "==2.21" },