← back to Ga Allsites

delete_orphan_ga4.py

21 lines

#!/usr/bin/env python3
"""Delete the 3 GA4 properties Steve approved (soft-delete, recoverable ~35 days)."""
import pathlib

from google.analytics.admin import AnalyticsAdminServiceClient

KEY = pathlib.Path.home()/".config"/"ga-analytics-agent"/"service-account.json"
TARGETS = [
 ("G-9K93LH6GH1", "properties/548357651", "Momentum DW (momentum.designerwallcoverings.com)"),
 ("G-QG3DGNYWZX", "properties/535741032", "goodquestion (goodquestion.ai)"),
 ("G-JZRGWSY1F6", "properties/535735055", "nosarabeachfrontrentals (nosarabeachfrontrentals.com)"),
]
c = AnalyticsAdminServiceClient.from_service_account_file(str(KEY))
for mid, prop, label in TARGETS:
    try:
        r = c.delete_property(name=prop)   # soft-delete -> Trash, recoverable ~35d
        state = getattr(r, "state", None)
        print(f"  ✅ DELETED {prop}  [{mid}]  {label}  (state={state})")
    except Exception as e:
        print(f"  ❌ FAILED  {prop}  [{mid}]  {label}: {type(e).__name__}: {str(e)[:120]}")