「MediaWiki:Common.js」の版間の差分
編集の要約なし |
編集の要約なし |
||
| 20行目: | 20行目: | ||
$(document).ready(function () { | $(document).ready(function () { | ||
if ($('.ga4- | // メインページ以外では動かさない | ||
if ($('.ga4-dashboard').length === 0) return; | |||
$.getJSON('/ | function formatNum(n) { | ||
return Number(n).toLocaleString('ja-JP'); | |||
} | |||
// 通常統計(初回1回読み込み) | |||
$.getJSON('/ga4_stats.json').done(function (data) { | |||
$('.ga4-total-users').text(formatNum(data.totalUsers)); | |||
$('.ga4-active-users').text(formatNum(data.activeUsers)); | |||
. | $('.ga4-pageviews').text(formatNum(data.pageviews)); | ||
$('.ga4- | $('.ga4-sessions').text(formatNum(data.sessions)); | ||
$('.ga4-updated').text(data.updated); | |||
}); | |||
// リアルタイム(30秒ごとに自動更新) | |||
function updateRealtime() { | |||
$.getJSON('/ga4_realtime.json').done(function (data) { | |||
$('.ga4-current-users').text(formatNum(data.currentUsers)); | |||
}); | }); | ||
} | |||
updateRealtime(); | |||
setInterval(updateRealtime, 30000); | |||
}); | }); | ||