: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-search-console): match quoted and domain-only property entries (#113114)
Tom Owerseb882476405b
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/google_search_console.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/google_search_console.pyindex e9f0d98860a4..278a0c2fa1a7 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/google_search_console.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/google_search_console.py@@ -129,6 +129,9 @@ def is_search_console_ui_url(site: str) -> bool:return site.strip().lower().startswith(SEARCH_CONSOLE_UI_PREFIX)+_PASTED_QUOTES = "'\"`\u2018\u2019\u201c\u201d"++def normalize_site_url(raw: str) -> str:"""Coerce a user-entered property URL toward Google's canonical form.@@ -136,11 +139,16 @@ def normalize_site_url(raw: str) -> str:trailing slash required) or ``sc-domain:example.com`` (domain). The API matches thesestrings byte-for-byte, but users routinely enter values that don't: a percent-encodedstring copied from a URL bar (``sc-domain%3Aexample.com``), the full Search Console UI- URL, or a URL-prefix property with the trailing slash dropped. Resolve the cases we can- handle unambiguously and leave the rest untouched — a bare hostname (no scheme, no- ``sc-domain:`` prefix) stays as-is because we can't tell which property type was meant.+ URL, a value still wrapped in the quotes it was copied with, or a URL-prefix property+ with the trailing slash dropped. Resolve the cases we can handle unambiguously and leave+ the rest untouched — a bare hostname (no scheme, no ``sc-domain:`` prefix) stays as-is+ because we can't tell which property type was meant."""site = raw.strip()+ # A value that opens with a quote was copied with its quotes. A quote elsewhere can belong+ # to a URL path, so only a leading one triggers the strip.+ if site[:1] in _PASTED_QUOTES:+ site = site.strip(_PASTED_QUOTES).strip()# The Search Console UI URL carries the property in its `resource_id` query param.if is_search_console_ui_url(site):@@ -166,15 +174,29 @@ def normalize_site_url(raw: str) -> str:def suggest_registered_site(site_url: str, registered: collections.abc.Iterable[str]) -> str | None:- """Return the registered property a bare-hostname entry most likely meant, else None.+ """Return the registered property an unmatched entry most likely meant, else None.``normalize_site_url`` deliberately leaves a bare hostname (e.g. ``example.com``)untouched because it can't tell a URL-prefix property (``https://example.com/``) froma domain property (``sc-domain:example.com``). When such an entry matches no property,check whether either canonical form *is* registered and point the user at it, so adead-end "not visible" error becomes "enter this exact value instead".++ A site's root URL entered where only its domain property is registered gets the domain+ property suggested. A URL with a path doesn't: the domain property covers the whole+ site, so syncing it would import more than the entry asked for."""- if urlparse(site_url).scheme or site_url.startswith("sc-domain:"):+ if site_url.startswith("sc-domain:"):+ return None+ parsed = urlparse(site_url)+ if parsed.scheme:+ if parsed.path not in ("", "/") or parsed.query or not parsed.hostname:+ return None+ registered_set = set(registered)+ host = parsed.hostname.lower()+ for domain in (host, host.removeprefix("www.")):+ if f"sc-domain:{domain}" in registered_set:+ return f"sc-domain:{domain}"return Nonehost = site_url.strip().strip("/").lower()if not host:diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/tests/test_google_search_console.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/tests/test_google_search_console.pyindex cb1c5fee069d..10fe06522d4b 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/tests/test_google_search_console.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/tests/test_google_search_console.py@@ -1014,6 +1014,13 @@ def test_throttle_spaces_requests_per_site(monkeypatch):("Https://example.com/Blog", "https://example.com/Blog/"),# Surrounding whitespace.(" https://example.com/ ", "https://example.com/"),+ # Quotes copied along with the value, matched or not.+ ("'sc-domain:example.com'", "sc-domain:example.com"),+ ("'sc-domain:example.com", "sc-domain:example.com"),+ ('"https://example.com"', "https://example.com/"),+ ("\u2018sc-domain:example.com\u2019", "sc-domain:example.com"),+ # A quote inside a URL path is part of the property, not a wrapper.+ ("https://example.com/blog'", "https://example.com/blog'/"),# The full Search Console UI URL — the property lives in resource_id.("https://search.google.com/search-console/performance/search-analytics"@@ -1046,8 +1053,12 @@ def test_normalize_site_url(raw, expected):("EXAMPLE.COM", ["sc-domain:example.com"], "sc-domain:example.com"),# No registered property matches — nothing to suggest.("plotlens.ai", ["https://other.com/"], None),- # Already scheme-qualified or a domain property: not ambiguous, so no suggestion.- ("https://plotlens.ai/", ["https://plotlens.ai/"], None),+ # A root URL whose site is registered only as a domain property.+ ("https://example.com/", ["sc-domain:example.com"], "sc-domain:example.com"),+ ("https://www.example.com/", ["sc-domain:example.com"], "sc-domain:example.com"),+ # A URL with a path would widen to the whole domain, so no suggestion.+ ("https://example.com/blog/", ["sc-domain:example.com"], None),+ ("https://plotlens.ai/", ["https://other.com/"], None),("sc-domain:plotlens.ai", ["sc-domain:plotlens.ai"], None),],)