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:
@@ -630,6 +630,26 @@ tr:hover td{background:#FAFBFC}
|
||||
<p style="font-size:.78rem;color:var(--light);margin-top:1rem">⚠️ پس از ذخیره، تغییرات فاویکون ممکن است نیاز به پاککردن کش مرورگر داشته باشد.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Google Analytics -->
|
||||
<div class="card" style="margin-top:1.2rem">
|
||||
<div class="card-header"><div class="card-title">📊 گوگل آنالیتیکس (Google Analytics)</div></div>
|
||||
<div class="modal-body">
|
||||
<p style="font-size:.83rem;color:var(--mid);margin-bottom:1.2rem;line-height:1.8">
|
||||
شناسه اندازهگیری گوگل آنالیتیکس ۴ (GA4) را وارد کنید تا کد رهگیری بهصورت خودکار در تمام صفحات سایت قرار گیرد.<br>
|
||||
<strong>فرمت:</strong> با <code>G-</code> شروع میشود — مثال: <code dir="ltr">G-XXXXXXXXXX</code><br>
|
||||
<span style="color:var(--light)">برای دریافت شناسه: analytics.google.com ← Admin ← Data Streams ← Measurement ID</span>
|
||||
</p>
|
||||
<div class="form-group">
|
||||
<label>Measurement ID</label>
|
||||
<input id="si-ga" dir="ltr" placeholder="G-XXXXXXXXXX" />
|
||||
</div>
|
||||
<div style="margin-top:1rem">
|
||||
<button class="btn btn-primary" onclick="saveSiteIdentity()">ذخیره شناسه آنالیتیکس</button>
|
||||
</div>
|
||||
<p style="font-size:.78rem;color:var(--light);margin-top:1rem">برای غیرفعالکردن، این فیلد را خالی کنید و ذخیره بزنید.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="page" id="page-security">
|
||||
@@ -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('ذخیره شد ✓ — برای اعمال فاویکون کش مرورگر را پاک کنید');
|
||||
|
||||
Reference in New Issue
Block a user