← back to Ga Allsites
poll_delete_ga4.py
40 lines
#!/usr/bin/env python3
"""Poll until SA gets Editor on 371997142, then soft-delete both. Every 90s, up to 30 tries (~45 min)."""
import pathlib
import time
from google.analytics.admin import AnalyticsAdminServiceClient
KEY = pathlib.Path.home() / ".config" / "ga-analytics-agent" / "service-account.json"
TARGETS = [
("properties/535741032", "goodquestion.ai"),
("properties/535735055", "nosarabeachfrontrentals.com"),
]
MAX_TRIES = 30
POLL_INTERVAL_S = 90
c = AnalyticsAdminServiceClient.from_service_account_file(str(KEY))
done = set()
for attempt in range(1, MAX_TRIES + 1):
for prop, label in TARGETS:
if prop in done:
continue
try:
c.delete_property(name=prop)
done.add(prop)
print(f"[try {attempt}] ✅ DELETED {prop} ({label})", flush=True)
except Exception as e:
msg = str(e)
if "not found" in msg.lower():
done.add(prop)
print(f"[try {attempt}] ✅ already gone {prop}", flush=True)
else:
print(f"[try {attempt}] ⏳ {prop}: {msg[:45]}", flush=True)
if len(done) == len(TARGETS):
print(f"\n✅ ALL DONE {len(done)}/2 (soft-delete, recoverable ~35d)", flush=True)
break
if attempt < MAX_TRIES:
time.sleep(POLL_INTERVAL_S)
else:
print(f"\n⚠️ gave up after ~45min, {len(done)}/2 deleted. Editor role likely still not set.", flush=True)