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.

fix(data-warehouse): match Apple's real App Store Connect report names (#82592)

posthog[bot]531e269989c6
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/app_store_connect.py b/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/app_store_connect.py
index e00953f172f7..7fed0e8e0203 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/app_store_connect.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/app_store_connect.py
@@ -664,6 +664,12 @@ def _ensure_report_request(
return (str(request_id) if request_id else None), True
+def _normalize_report_name(name: str) -> str:
+ # Apple's report names drift in case, spacing, and hyphenation ("Pre-Orders" vs "Pre-orders").
+ # Match on alphanumerics only, so a cosmetic rename cannot silently blank a stream.
+ return re.sub(r"[^a-z0-9]", "", name.casefold())
+
+
def _find_analytics_report(
session: requests.Session,
token_provider: AppStoreConnectTokenProvider,
@@ -681,9 +687,11 @@ def _find_analytics_report(
if row.get("name") and row.get("id"):
report_ids[str(row["name"])] = str(row["id"])
+ by_normalized = {_normalize_report_name(name): report_id for name, report_id in report_ids.items()}
for name in config.analytics_report_names:
- if name in report_ids:
- return report_ids[name]
+ report_id = by_normalized.get(_normalize_report_name(name))
+ if report_id is not None:
+ return report_id
logger.warning(
f"App Store Connect: no report named {config.analytics_report_names} under this request "
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/settings.py
index de09093fc264..970259c6a263 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/settings.py
@@ -239,12 +239,12 @@ APP_STORE_CONNECT_ENDPOINTS: dict[str, AppStoreConnectEndpointConfig] = {
),
"analytics_app_store_downloads": _analytics_endpoint(
"analytics_app_store_downloads",
- ("App Store Downloads Standard", "App Store Downloads"),
+ ("App Downloads Standard", "App Downloads"),
"COMMERCE",
),
"analytics_installations_deletions": _analytics_endpoint(
"analytics_installations_deletions",
- ("App Store Installations and Deletions Standard", "App Store Installations and Deletions"),
+ ("App Store Installation and Deletion Standard", "App Store Installation and Deletion"),
"APP_USAGE",
),
"analytics_discovery_engagement": _analytics_endpoint(
@@ -259,7 +259,7 @@ APP_STORE_CONNECT_ENDPOINTS: dict[str, AppStoreConnectEndpointConfig] = {
),
"analytics_app_store_preorders": _analytics_endpoint(
"analytics_app_store_preorders",
- ("App Store Pre-orders Standard", "App Store Pre-orders"),
+ ("App Store Pre-Orders Standard", "App Store Pre-Orders"),
"COMMERCE",
),
"analytics_app_clip_usage": _analytics_endpoint(
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/tests/test_app_store_connect.py b/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/tests/test_app_store_connect.py
index a51f1db641e5..090b5349b20a 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/tests/test_app_store_connect.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/tests/test_app_store_connect.py
@@ -20,10 +20,12 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.app_store_
AppStoreConnectResumeConfig,
AppStoreConnectTokenProvider,
AppStoreConnectUrlError,
+ _find_analytics_report,
_flatten_resource,
_get,
_normalize_private_key,
_normalize_report_column,
+ _Page,
_parse_report,
_require_api_url,
app_store_connect_source,
@@ -861,6 +863,38 @@ class TestAnalyticsReportStreams:
assert response.sort_mode == "asc"
+class TestFindAnalyticsReport:
+ def _resolve(self, endpoint: str, apple_name: str) -> str | None:
+ config = APP_STORE_CONNECT_ENDPOINTS[endpoint]
+ page = _Page(
+ resources=[
+ _resource("analyticsReports", "REP1", name=apple_name, category=config.analytics_report_category)
+ ],
+ included=[],
+ next_url=None,
+ )
+ with patch(f"{MODULE}._iter_pages", return_value=iter([page])):
+ return _find_analytics_report(MagicMock(), MagicMock(), MagicMock(), config, "REQ1")
+
+ @parameterized.expand(
+ [
+ ("analytics_app_store_downloads", "App Downloads Standard"),
+ ("analytics_installations_deletions", "App Store Installation and Deletion Standard"),
+ ("analytics_app_store_preorders", "App Store Pre-Orders Standard"),
+ ]
+ )
+ def test_configured_names_resolve_the_report_apple_actually_returns(self, endpoint: str, apple_name: str) -> None:
+ # These three streams asked for names Apple never returns, so the lookup resolved nothing and
+ # the stream synced an empty table without failing. Fixtures elsewhere use "App Sessions
+ # Standard", spelled the same here and at Apple, so they never exercised the mismatch.
+ assert self._resolve(endpoint, apple_name) == "REP1"
+
+ def test_match_tolerates_case_and_hyphen_drift(self) -> None:
+ # Apple's casing of "Pre-Orders" has drifted before; normalization must resolve it without a
+ # config change so a cosmetic rename can't silently blank the stream again.
+ assert self._resolve("analytics_app_store_preorders", "App Store Pre-orders Standard") == "REP1"
+
+
class TestReportColumnNames:
@parameterized.expand(
[