feat(analytics): admin field for Google Analytics (GA4) ID
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:
@@ -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 />
|
||||
|
||||
Reference in New Issue
Block a user