From 82d9720e255d9152347edbd2f89893c8e557c41a Mon Sep 17 00:00:00 2001 From: "soroush.asadi" Date: Mon, 15 Jun 2026 15:33:03 +0330 Subject: [PATCH] feat(analytics): admin field for Google Analytics (GA4) ID MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a "Measurement ID" input under admin → Site Identity. The value is stored as identity/ga_id (existing bulk-settings endpoint, no API change). When set, _Layout injects the GA4 gtag.js snippet into on every page (home, blog, gallery, posts). Empty value = disabled. Co-Authored-By: Claude Opus 4.8 --- DrSousan.Api/Pages/Shared/_Layout.cshtml | 12 ++++++++++++ DrSousan.Api/wwwroot/admin/index.html | 24 +++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/DrSousan.Api/Pages/Shared/_Layout.cshtml b/DrSousan.Api/Pages/Shared/_Layout.cshtml index 9157ab0..83be79b 100644 --- a/DrSousan.Api/Pages/Shared/_Layout.cshtml +++ b/DrSousan.Api/Pages/Shared/_Layout.cshtml @@ -6,12 +6,24 @@ .ToListAsync(); var _logoUrl = _identity.FirstOrDefault(s => s.Key == "logo")?.Value ?? ""; var _faviconUrl = _identity.FirstOrDefault(s => s.Key == "favicon")?.Value ?? ""; + var _gaId = (_identity.FirstOrDefault(s => s.Key == "ga_id")?.Value ?? "").Trim(); } + @if (!string.IsNullOrEmpty(_gaId)) + { + + + + } @RenderSection("Head", required: false) diff --git a/DrSousan.Api/wwwroot/admin/index.html b/DrSousan.Api/wwwroot/admin/index.html index 290316f..b3179d3 100644 --- a/DrSousan.Api/wwwroot/admin/index.html +++ b/DrSousan.Api/wwwroot/admin/index.html @@ -630,6 +630,26 @@ tr:hover td{background:#FAFBFC}

⚠️ پس از ذخیره، تغییرات فاویکون ممکن است نیاز به پاک‌کردن کش مرورگر داشته باشد.

+ + +
+
📊 گوگل آنالیتیکس (Google Analytics)
+ +
@@ -1464,6 +1484,7 @@ async function loadSiteIdentity() { // Set hidden inputs document.getElementById('si-logo').value = vals.logo || ''; document.getElementById('si-favicon').value = vals.favicon || ''; + document.getElementById('si-ga').value = vals.ga_id || ''; // Show previews showPreview('prev-si-logo', vals.logo || ''); showPreview('prev-si-favicon', vals.favicon || ''); @@ -1486,9 +1507,10 @@ function updateSiteIdentityPreview(logoUrl, faviconUrl) { async function saveSiteIdentity() { const logo = document.getElementById('si-logo').value; const favicon = document.getElementById('si-favicon').value; + const ga_id = (document.getElementById('si-ga').value || '').trim(); await api('/api/settings/identity', { method: 'PUT', - body: JSON.stringify({ settings: { logo, favicon } }) + body: JSON.stringify({ settings: { logo, favicon, ga_id } }) }); updateSiteIdentityPreview(logo, favicon); toast('ذخیره شد ✓ — برای اعمال فاویکون کش مرورگر را پاک کنید');