: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): suggest the exact property for a bare host (#65448)
Tom Owers9b2b5557eccf
diff --git a/posthog/temporal/data_imports/sources/google_search_console/google_search_console.py b/posthog/temporal/data_imports/sources/google_search_console/google_search_console.pyindex c24ca4f494e6..e0903a83a701 100644--- a/posthog/temporal/data_imports/sources/google_search_console/google_search_console.py+++ b/posthog/temporal/data_imports/sources/google_search_console/google_search_console.py@@ -140,6 +140,27 @@ def normalize_site_url(raw: str) -> str:return site+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.++ ``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/``) from+ a 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 a+ dead-end "not visible" error becomes "enter this exact value instead".+ """+ if urlparse(site_url).scheme or site_url.startswith("sc-domain:"):+ return None+ host = site_url.strip().strip("/").lower()+ if not host:+ return None+ registered_set = set(registered)+ for candidate in (f"https://{host}/", f"http://{host}/", f"sc-domain:{host}"):+ if candidate in registered_set:+ return candidate+ return None++def _credentials(integration_id: int, team_id: int) -> OAuthCredentials:# Temporal activities run in a thread pool where Django DB connections can go# stale between uses (Postgres closes the connection server-side). This isdiff --git a/posthog/temporal/data_imports/sources/google_search_console/source.py b/posthog/temporal/data_imports/sources/google_search_console/source.pyindex 537e348c68a7..2f22290bf9c4 100644--- a/posthog/temporal/data_imports/sources/google_search_console/source.py+++ b/posthog/temporal/data_imports/sources/google_search_console/source.py@@ -27,6 +27,7 @@ from posthog.temporal.data_imports.sources.google_search_console.google_search_cgoogle_search_console_source,list_sites,normalize_site_url,+ suggest_registered_site,)from posthog.temporal.data_imports.sources.google_search_console.settings import (SEARCH_ANALYTICS_INCREMENTAL_FIELD,@@ -149,9 +150,17 @@ class GoogleSearchConsoleSource(except Exception as e:return False, f"Failed to list Google Search Console sites: {e}"- normalized = {site.get("siteUrl"): site.get("permissionLevel") for site in sites}+ normalized = {url: site.get("permissionLevel") for site in sites if (url := site.get("siteUrl")) is not None}site_url = normalize_site_url(config.site_url)if site_url not in normalized:+ suggestion = suggest_registered_site(site_url, normalized.keys())+ if suggestion is not None:+ return (+ False,+ f"'{site_url}' isn't a Search Console property, but the connected account has "+ f"'{suggestion}'. Enter the property exactly as Search Console lists it — '{suggestion}' — "+ f"and try again.",+ )return (False,f"Site '{site_url}' is not visible to the connected Google account. Verify the property URL "diff --git a/posthog/temporal/data_imports/sources/google_search_console/tests/test_google_search_console.py b/posthog/temporal/data_imports/sources/google_search_console/tests/test_google_search_console.pyindex 0d5cff02b7d2..9faaad17dcfb 100644--- a/posthog/temporal/data_imports/sources/google_search_console/tests/test_google_search_console.py+++ b/posthog/temporal/data_imports/sources/google_search_console/tests/test_google_search_console.py@@ -24,6 +24,7 @@ from posthog.temporal.data_imports.sources.google_search_console.google_search_c_row_to_dict,google_search_console_source,normalize_site_url,+ suggest_registered_site,)TODAY = dt.date(2026, 4, 30)@@ -461,3 +462,29 @@ def test_throttle_spaces_requests_per_site(monkeypatch):)def test_normalize_site_url(raw, expected):assert normalize_site_url(raw) == expected+++ "site_url,registered,expected",+ [+ # Bare hostname matches a registered URL-prefix property.+ ("plotlens.ai", ["https://plotlens.ai/"], "https://plotlens.ai/"),+ ("buyticketbrasil.com", ["https://buyticketbrasil.com/"], "https://buyticketbrasil.com/"),+ # Bare hostname matches a registered domain property.+ ("autocomply.dev", ["sc-domain:autocomply.dev"], "sc-domain:autocomply.dev"),+ # URL-prefix preferred when both forms are registered.+ ("example.com", ["sc-domain:example.com", "https://example.com/"], "https://example.com/"),+ # A trailing slash on the bare hostname is tolerated.+ ("plotlens.ai/", ["https://plotlens.ai/"], "https://plotlens.ai/"),+ # An uppercase bare hostname is lowercased to match Google's canonical property names.+ ("PlotLens.AI", ["https://plotlens.ai/"], "https://plotlens.ai/"),+ ("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),+ ("sc-domain:plotlens.ai", ["sc-domain:plotlens.ai"], None),+ ],+)+def test_suggest_registered_site(site_url, registered, expected):+ assert suggest_registered_site(site_url, registered) == expecteddiff --git a/posthog/temporal/data_imports/sources/google_search_console/tests/test_google_search_console_source.py b/posthog/temporal/data_imports/sources/google_search_console/tests/test_google_search_console_source.pyindex f44e8ed657dc..ad3bd308e106 100644--- a/posthog/temporal/data_imports/sources/google_search_console/tests/test_google_search_console_source.py+++ b/posthog/temporal/data_imports/sources/google_search_console/tests/test_google_search_console_source.py@@ -182,6 +182,24 @@ def test_validate_credentials_rejects_unknown_site():assert "is not visible to the connected Google account" in (message or "")+def test_validate_credentials_suggests_registered_property_for_bare_hostname():+ # User entered a bare hostname; the account has the URL-prefix property. Point them+ # at the exact string to paste rather than the dead-end "not visible" message.+ config = GoogleSearchConsoleSourceConfig(site_url="plotlens.ai", google_search_console_integration_id=1)+ with (+ mock.patch("posthog.temporal.data_imports.sources.google_search_console.source.google_search_console_session"),+ mock.patch(+ "posthog.temporal.data_imports.sources.google_search_console.source.list_sites",+ return_value=[{"siteUrl": "https://plotlens.ai/", "permissionLevel": "siteOwner"}],+ ),+ ):+ ok, message = GoogleSearchConsoleSource().validate_credentials(config, team_id=1)++ assert ok is False+ assert "https://plotlens.ai/" in (message or "")+ assert "is not visible to the connected Google account" not in (message or "")++def test_validate_credentials_rejects_unverified_user():with (mock.patch("posthog.temporal.data_imports.sources.google_search_console.source.google_search_console_session"),