omnirank 0.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- omnirank/__init__.py +14 -0
- omnirank/__main__.py +6 -0
- omnirank/adapters/__init__.py +202 -0
- omnirank/adapters/astro.py +338 -0
- omnirank/adapters/base.py +372 -0
- omnirank/adapters/html.py +561 -0
- omnirank/adapters/jsx.py +340 -0
- omnirank/adapters/nextjs.py +692 -0
- omnirank/aeo/__init__.py +9 -0
- omnirank/aeo/extract.py +383 -0
- omnirank/aeo/propose.py +84 -0
- omnirank/aeo/rules.py +964 -0
- omnirank/aeo/runner.py +148 -0
- omnirank/applicability.py +98 -0
- omnirank/apply/__init__.py +23 -0
- omnirank/apply/engine.py +1254 -0
- omnirank/apply/journal.py +139 -0
- omnirank/apply/patch.py +144 -0
- omnirank/audit.py +185 -0
- omnirank/bands.py +106 -0
- omnirank/brief/__init__.py +0 -0
- omnirank/brief/analyze.py +197 -0
- omnirank/brief/constants.py +89 -0
- omnirank/brief/cost.py +62 -0
- omnirank/brief/egress.py +23 -0
- omnirank/brief/fetchpages.py +239 -0
- omnirank/brief/render.py +151 -0
- omnirank/brief/runner.py +369 -0
- omnirank/brief/serp.py +274 -0
- omnirank/brief/text.py +181 -0
- omnirank/cli.py +844 -0
- omnirank/clock.py +22 -0
- omnirank/cms/__init__.py +1 -0
- omnirank/cms/runner.py +170 -0
- omnirank/cms/wordpress.py +495 -0
- omnirank/cms/wordpress_apply.py +508 -0
- omnirank/cms/wordpress_plan.py +280 -0
- omnirank/config.py +81 -0
- omnirank/connect/__init__.py +4 -0
- omnirank/connect/bing.py +284 -0
- omnirank/connect/cloud_setup.py +43 -0
- omnirank/connect/confirm.py +242 -0
- omnirank/connect/constants.py +226 -0
- omnirank/connect/doctor.py +270 -0
- omnirank/connect/ga4.py +749 -0
- omnirank/connect/ga4_ai.py +123 -0
- omnirank/connect/google_auth.py +657 -0
- omnirank/connect/gsc.py +630 -0
- omnirank/connect/gsc_reports.py +169 -0
- omnirank/connect/http.py +310 -0
- omnirank/connect/indexnow.py +373 -0
- omnirank/connect/naver.py +536 -0
- omnirank/connect/runner.py +515 -0
- omnirank/connect/runner_ga4_ai.py +59 -0
- omnirank/connect/runner_more.py +489 -0
- omnirank/connect/runner_regional.py +260 -0
- omnirank/connect/secrets.py +190 -0
- omnirank/connect/urlcheck.py +41 -0
- omnirank/connect/yandex.py +350 -0
- omnirank/crawl/__init__.py +11 -0
- omnirank/crawl/analyze.py +493 -0
- omnirank/crawl/crawler.py +491 -0
- omnirank/crawl/custom.py +175 -0
- omnirank/crawl/export.py +67 -0
- omnirank/crawl/fetcher.py +212 -0
- omnirank/crawl/parse.py +102 -0
- omnirank/crawl/render.py +148 -0
- omnirank/crawl/robotsgate.py +198 -0
- omnirank/crawl/runner.py +295 -0
- omnirank/crawl/sitemap.py +99 -0
- omnirank/crawl/text.py +20 -0
- omnirank/crawl/urls.py +100 -0
- omnirank/crawlers.py +564 -0
- omnirank/data/ai_crawlers.json +269 -0
- omnirank/data/ai_referrers.json +42 -0
- omnirank/fetch.py +107 -0
- omnirank/fixes/__init__.py +92 -0
- omnirank/fixes/base.py +232 -0
- omnirank/fixes/canonical.py +243 -0
- omnirank/fixes/schema.py +126 -0
- omnirank/formats.py +134 -0
- omnirank/framework.py +223 -0
- omnirank/gates/__init__.py +48 -0
- omnirank/gates/aeo.py +114 -0
- omnirank/gates/contradictions.py +280 -0
- omnirank/gates/crawler_policy.py +85 -0
- omnirank/gates/geo.py +152 -0
- omnirank/gates/hygiene.py +81 -0
- omnirank/gates/jsonld.py +282 -0
- omnirank/gates/onpage.py +177 -0
- omnirank/gates/perf.py +115 -0
- omnirank/gates/security.py +264 -0
- omnirank/gates/seo.py +118 -0
- omnirank/gates/site.py +248 -0
- omnirank/geo_artifacts.py +199 -0
- omnirank/html.py +79 -0
- omnirank/keywords/__init__.py +5 -0
- omnirank/keywords/constants.py +69 -0
- omnirank/keywords/engine.py +384 -0
- omnirank/keywords/report.py +143 -0
- omnirank/keywords/runner.py +160 -0
- omnirank/keywords/source.py +60 -0
- omnirank/keywords/text.py +45 -0
- omnirank/locator.py +480 -0
- omnirank/logs/__init__.py +0 -0
- omnirank/logs/analyze.py +127 -0
- omnirank/logs/bots.py +69 -0
- omnirank/logs/ipranges.py +191 -0
- omnirank/logs/parse.py +452 -0
- omnirank/logs/paths.py +22 -0
- omnirank/logs/privacy.py +105 -0
- omnirank/logs/runner.py +179 -0
- omnirank/mcp_server.py +1480 -0
- omnirank/netguard.py +525 -0
- omnirank/packs/__init__.py +6 -0
- omnirank/packs/backlinks.py +535 -0
- omnirank/packs/blog.py +544 -0
- omnirank/packs/blog_cross.py +468 -0
- omnirank/packs/crawlers.py +23 -0
- omnirank/packs/entity.py +492 -0
- omnirank/packs/feeds.py +150 -0
- omnirank/packs/frontmatter.py +59 -0
- omnirank/packs/gsc.py +421 -0
- omnirank/packs/local.py +879 -0
- omnirank/packs/mdscan.py +326 -0
- omnirank/packs/miniyaml.py +378 -0
- omnirank/packs/model.py +46 -0
- omnirank/packs/product.py +979 -0
- omnirank/packs/refresh.py +165 -0
- omnirank/packs/runner.py +277 -0
- omnirank/packs/sitescan.py +294 -0
- omnirank/packs/textsafe.py +79 -0
- omnirank/packs/xmlsafe.py +92 -0
- omnirank/page.py +42 -0
- omnirank/registry.py +302 -0
- omnirank/report.py +251 -0
- omnirank/report_cmd/__init__.py +7 -0
- omnirank/report_cmd/delta.py +58 -0
- omnirank/report_cmd/files.py +64 -0
- omnirank/report_cmd/model.py +208 -0
- omnirank/report_cmd/notify.py +195 -0
- omnirank/report_cmd/pdf.py +83 -0
- omnirank/report_cmd/portfolio.py +342 -0
- omnirank/report_cmd/render.py +379 -0
- omnirank/report_cmd/runner.py +267 -0
- omnirank/robots.py +172 -0
- omnirank/scanner/__init__.py +10 -0
- omnirank/scanner/badge.py +90 -0
- omnirank/scanner/cache.py +69 -0
- omnirank/scanner/cli.py +96 -0
- omnirank/scanner/engine.py +289 -0
- omnirank/scanner/limits.py +98 -0
- omnirank/scanner/server.py +143 -0
- omnirank/scanner/service.py +328 -0
- omnirank/schema/__init__.py +13 -0
- omnirank/schema/catalog.py +679 -0
- omnirank/schema/catalog_specs.py +350 -0
- omnirank/schema/core.py +306 -0
- omnirank/schema/extract.py +396 -0
- omnirank/schema/gate.py +121 -0
- omnirank/schema/runner.py +213 -0
- omnirank/schema/validate.py +504 -0
- omnirank/schema/vocab.py +305 -0
- omnirank/schemas/omnirank.config.schema.json +268 -0
- omnirank/track/__init__.py +0 -0
- omnirank/track/ai_prompts.py +207 -0
- omnirank/track/analysis.py +197 -0
- omnirank/track/constants.py +155 -0
- omnirank/track/cost.py +229 -0
- omnirank/track/discover.py +277 -0
- omnirank/track/discover_cli.py +309 -0
- omnirank/track/discover_constants.py +95 -0
- omnirank/track/engines.py +216 -0
- omnirank/track/estimate_view.py +212 -0
- omnirank/track/history.py +261 -0
- omnirank/track/runner.py +586 -0
- omnirank/track/stats.py +138 -0
- omnirank/track/storage.py +128 -0
- omnirank-0.5.0.dist-info/METADATA +47 -0
- omnirank-0.5.0.dist-info/RECORD +183 -0
- omnirank-0.5.0.dist-info/WHEEL +5 -0
- omnirank-0.5.0.dist-info/entry_points.txt +2 -0
- omnirank-0.5.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"""`omnirank connect ga4 ai-referrals` (spec 13.4 B4): sessions, engaged sessions and key
|
|
2
|
+
events from AI-assistant referrers next to the Organic Search trend, over the last N days.
|
|
3
|
+
|
|
4
|
+
Two read-only Data API ``runReport`` calls through the existing ``Ga4Client`` (nothing new is
|
|
5
|
+
sent to Google; the same documented dimension/metric names):
|
|
6
|
+
|
|
7
|
+
1. ``date`` x ``sessionSource`` filtered to the session sources in ``data/ai_referrers.json``;
|
|
8
|
+
2. ``date`` filtered to the channel group ``Organic Search``.
|
|
9
|
+
|
|
10
|
+
The AI numbers are a LOWER BOUND (``ga4.LOWER_BOUND_CAVEAT``). The window ends YESTERDAY
|
|
11
|
+
(today's data is incomplete). Only aggregate numbers are read: no user-level data, no PII.
|
|
12
|
+
"""
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import re
|
|
16
|
+
from datetime import date, timedelta
|
|
17
|
+
|
|
18
|
+
from .. import clock
|
|
19
|
+
from . import ga4
|
|
20
|
+
|
|
21
|
+
MAX_DAYS = 365
|
|
22
|
+
MAX_ROWS = 100_000
|
|
23
|
+
_SINCE = re.compile(r"([1-9][0-9]{0,2})[dD]")
|
|
24
|
+
_GA4_DATE = re.compile(r"[0-9]{8}")
|
|
25
|
+
_METRICS = ("sessions", "engagedSessions", "keyEvents")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def parse_since(value: str) -> int:
|
|
29
|
+
m = _SINCE.fullmatch(value or "")
|
|
30
|
+
days = int(m.group(1)) if m else 0
|
|
31
|
+
if not 1 <= days <= MAX_DAYS:
|
|
32
|
+
raise ga4.Ga4Error(f"--since {str(value)[:20]!r} must be a number of days like 28d "
|
|
33
|
+
f"(1d..{MAX_DAYS}d)")
|
|
34
|
+
return days
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def window(days: int) -> tuple[str, str]:
|
|
38
|
+
end = clock.today() - timedelta(days=1)
|
|
39
|
+
start = end - timedelta(days=days - 1)
|
|
40
|
+
return start.isoformat(), end.isoformat()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _day(value: str, start: date, end: date) -> date | None:
|
|
44
|
+
if not _GA4_DATE.fullmatch(value):
|
|
45
|
+
return None
|
|
46
|
+
try:
|
|
47
|
+
d = date(int(value[:4]), int(value[4:6]), int(value[6:]))
|
|
48
|
+
except ValueError:
|
|
49
|
+
return None
|
|
50
|
+
return d if start <= d <= end else None
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _zero() -> dict:
|
|
54
|
+
return {m: 0 for m in _METRICS}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _add(cell: dict, metrics: dict) -> None:
|
|
58
|
+
for m in _METRICS:
|
|
59
|
+
cell[m] += metrics.get(m, 0)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def ai_vs_organic(client: ga4.Ga4Client, property_id: str, days: int, referrers: dict
|
|
63
|
+
) -> dict:
|
|
64
|
+
prop = ga4.validate_property_id(property_id)
|
|
65
|
+
start, end = window(days)
|
|
66
|
+
d_start, d_end = date.fromisoformat(start), date.fromisoformat(end)
|
|
67
|
+
_, _, ai_filter = ga4.preset("ai-referrals", referrers)
|
|
68
|
+
_, _, organic_filter = ga4.preset("organic-landing")
|
|
69
|
+
ai_res = client.run_report(prop, start, end, ["date", "sessionSource"], list(_METRICS),
|
|
70
|
+
dimension_filter=ai_filter, max_rows=MAX_ROWS)
|
|
71
|
+
org_res = client.run_report(prop, start, end, ["date"], list(_METRICS),
|
|
72
|
+
dimension_filter=organic_filter, max_rows=MAX_ROWS)
|
|
73
|
+
known = {s for e in referrers["entries"] for s in e["session_sources"]}
|
|
74
|
+
daily = {(d_start + timedelta(days=i)).isoformat(): {"ai": _zero(), "organic": _zero()}
|
|
75
|
+
for i in range(days)}
|
|
76
|
+
skipped = 0
|
|
77
|
+
ai_rows = []
|
|
78
|
+
for row in ai_res.rows:
|
|
79
|
+
day = _day(row["dimensions"].get("date", ""), d_start, d_end)
|
|
80
|
+
source = row["dimensions"].get("sessionSource", "").lower()
|
|
81
|
+
if day is None or source not in known:
|
|
82
|
+
skipped += 1
|
|
83
|
+
continue
|
|
84
|
+
_add(daily[day.isoformat()]["ai"], row["metrics"])
|
|
85
|
+
ai_rows.append(row)
|
|
86
|
+
for row in org_res.rows:
|
|
87
|
+
day = _day(row["dimensions"].get("date", ""), d_start, d_end)
|
|
88
|
+
if day is None:
|
|
89
|
+
skipped += 1
|
|
90
|
+
continue
|
|
91
|
+
_add(daily[day.isoformat()]["organic"], row["metrics"])
|
|
92
|
+
ai_tot, org_tot = _zero(), _zero()
|
|
93
|
+
for cell in daily.values():
|
|
94
|
+
_add(ai_tot, cell["ai"])
|
|
95
|
+
_add(org_tot, cell["organic"])
|
|
96
|
+
summary = ga4.ai_referral_summary(ai_rows, referrers)
|
|
97
|
+
trend = None
|
|
98
|
+
if days >= 2:
|
|
99
|
+
keys = list(daily)
|
|
100
|
+
half = days // 2
|
|
101
|
+
|
|
102
|
+
def part(ks: list[str]) -> dict:
|
|
103
|
+
return {"start": ks[0], "end": ks[-1],
|
|
104
|
+
"ai_sessions": sum(daily[k]["ai"]["sessions"] for k in ks),
|
|
105
|
+
"organic_sessions": sum(daily[k]["organic"]["sessions"] for k in ks)}
|
|
106
|
+
trend = {"first_half": part(keys[:half]), "second_half": part(keys[half:])}
|
|
107
|
+
ratio = (round(ai_tot["sessions"] * 100 / org_tot["sessions"], 2)
|
|
108
|
+
if org_tot["sessions"] else None)
|
|
109
|
+
return {
|
|
110
|
+
"property": prop, "report": "ai-referrals", "startDate": start, "endDate": end,
|
|
111
|
+
"days": days, "lower_bound": True, "caveat": ga4.LOWER_BOUND_CAVEAT,
|
|
112
|
+
"list_checked_on": referrers["checked_on"],
|
|
113
|
+
"ai": {"totals": ai_tot, "by_assistant": summary["by_assistant"]},
|
|
114
|
+
"organic": {"channel_group": "Organic Search", "totals": org_tot},
|
|
115
|
+
"ai_sessions_per_100_organic": ratio,
|
|
116
|
+
"trend": trend,
|
|
117
|
+
"daily": [{"date": k, "ai_sessions": v["ai"]["sessions"],
|
|
118
|
+
"organic_sessions": v["organic"]["sessions"]} for k, v in daily.items()],
|
|
119
|
+
"skipped_rows": skipped + ai_res.skipped + org_res.skipped,
|
|
120
|
+
"truncated": ai_res.truncated or org_res.truncated,
|
|
121
|
+
"thresholded": bool(ai_res.thresholded or org_res.thresholded),
|
|
122
|
+
"requests": ai_res.requests + org_res.requests,
|
|
123
|
+
}
|