feat(analytics): admin field for Google Analytics (GA4) ID
CI/CD / CI · dotnet build (push) Successful in 1m1s
CI/CD / Deploy · drsousan (push) Successful in 25s

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 <head>
on every page (home, blog, gallery, posts). Empty value = disabled.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
soroush.asadi
2026-06-15 15:33:03 +03:30
parent 99a54be3ac
commit 82d9720e25
2 changed files with 35 additions and 1 deletions
+12
View File
@@ -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();
}
<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
@if (!string.IsNullOrEmpty(_gaId))
{
<!-- Google Analytics (GA4) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=@_gaId"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '@Html.Raw(_gaId)');
</script>
}
@RenderSection("Head", required: false)
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />