: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
fix(google-analytics): accept the property id from a ga4 url (#119169)
Tom Owersb0c20ed80caa
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/google_analytics.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/google_analytics.pyindex 87e8eec6649c..cdd5302e017f 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/google_analytics.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/google_analytics.py@@ -131,10 +131,13 @@ def google_analytics_session(integration_id: int, team_id: int) -> AuthorizedSesdef normalize_property_id(property_id: str) -> str:- """Accept both a bare numeric ID and the `properties/123` resource name users may paste."""+ """Accept a bare numeric ID, the `properties/123` resource name, and the `p123` segment of a+ GA4 web UI URL, which users may paste."""cleaned = property_id.strip()if cleaned.startswith("properties/"):cleaned = cleaned[len("properties/") :]+ elif len(cleaned) > 1 and cleaned[0] in "pP" and cleaned[1:].isdigit():+ cleaned = cleaned[1:]return cleaneddiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/tests/test_google_analytics_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/tests/test_google_analytics_source.pyindex a4d972adf434..8662e0c0ce6f 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/tests/test_google_analytics_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/tests/test_google_analytics_source.py@@ -227,7 +227,8 @@ def test_validate_credentials_handles_missing_integration():assert "matching query" not in (message or "")-def test_validate_credentials_succeeds_when_metadata_readable():[email protected]("property_id", ["123456789", "properties/123456789", "p123456789"])+def test_validate_credentials_succeeds_when_metadata_readable(property_id):with (mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.google_analytics.source.google_analytics_session"@@ -235,12 +236,13 @@ def test_validate_credentials_succeeds_when_metadata_readable():mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.google_analytics.source.get_property_metadata",return_value={"dimensions": [], "metrics": []},- ),+ ) as get_metadata,):- ok, message = GoogleAnalyticsSource().validate_credentials(_config(), team_id=1)+ ok, message = GoogleAnalyticsSource().validate_credentials(_config(property_id), team_id=1)assert ok is Trueassert message is None+ assert get_metadata.call_args.args[1] == "123456789"def test_retryable_errors_cover_exhausted_quota_retries():