← back to Ga Allsites
create_shell_ga4.py
43 lines
#!/usr/bin/env python3
"""Create GA4 properties for the 25 zero-tracking 'shell' sites in the
DesignerWallcoverings GA4 account (15714274, SA has Editor). Steve-run.
Writes G-ids to gtm/shell-ga4.json; then Claude injects the gtag per site.
Usage: python3 ~/Projects/ga-allsites/create_shell_ga4.py
"""
import json
import pathlib
from google.analytics.admin import AnalyticsAdminServiceClient, DataStream, Property
KEY = pathlib.Path.home()/".config"/"ga-analytics-agent"/"service-account.json"
ACCT = "accounts/15714274"
SHELLS = {
"818butler.com":"818 Butler","abramscivic.com":"Abrams Civic","abramsdirectory.com":"Abrams Directory",
"abramsguide.com":"Abrams Guide","abramsindex.com":"Abrams Index","abramsindustries.com":"Abrams Industries",
"abramsintelligence.com":"Abrams Intelligence","abramslive.com":"Abrams Live","abramslocal.com":"Abrams Local",
"abramsmaps.com":"Abrams Maps","abramsmarkets.com":"Abrams Markets","abramsos.com":"Abrams OS",
"abramsprotection.com":"Abrams Protection","abramsspace.com":"Abrams Space","abramsterminal.com":"Abrams Terminal",
"abramsvc.com":"Abrams VC","allnewsdaily.com":"All News Daily","beverlyhillsbutler.com":"Beverly Hills Butler",
"beverlyhillsvideos.com":"Beverly Hills Videos","bhbutler.com":"BH Butler","boulevardbutler.com":"Boulevard Butler",
"cypresawards.com":"Cypres Awards","nodailyworries.com":"No Daily Worries","petitionyour.com":"Petition Your",
"studentdebtcrisis.org":"Student Debt Crisis"}
client = AnalyticsAdminServiceClient.from_service_account_file(str(KEY))
outf = pathlib.Path(__file__).parent / "gtm" / "shell-ga4.json"
outf.parent.mkdir(parents=True, exist_ok=True)
out = json.loads(outf.read_text()) if outf.exists() else {}
for dom, name in SHELLS.items():
if out.get(dom):
print(f"SKIP {dom} (already {out[dom]})"); continue
try:
p = client.create_property(property=Property(parent=ACCT, display_name=name,
time_zone="America/Los_Angeles", currency_code="USD", industry_category="ONLINE_COMMUNITIES"))
s = client.create_data_stream(parent=p.name, data_stream=DataStream(
type_=DataStream.DataStreamType.WEB_DATA_STREAM, display_name=f"{name} Web",
web_stream_data=DataStream.WebStreamData(default_uri=f"https://{dom}")))
out[dom] = s.web_stream_data.measurement_id
print(f"CREATED {dom:32} {out[dom]}")
except Exception as e: # noqa: BLE001
print(f"ERR {dom:32} {type(e).__name__}: {str(e)[:90]}")
outf.write_text(json.dumps(out, indent=2))
print(f"\n{len(out)}/25 -> {outf}. Now tell Claude 'inject the shells'.")