{% extends '@admin/default_frame.twig' %}
{% set menus = ['site_kit', 'gsc_query'] %}
{% block title %}Site Kit{% endblock %}
{% block sub_title %}ダッシュボード{% endblock %}
{% block stylesheet %}{% endblock stylesheet %}
{% block javascript %}
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages': ['line', 'corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
let classicOptions = {
height: 500,
// Gives each series an axis that matches the vAxes number below.
series: {
0: {targetAxisIndex: 0},
1: {targetAxisIndex: 1}
},
vAxes: {
// Adds titles to each axis.
0: {title: 'クリック数'},
1: {title: '表示回数'}
}
};
let data = google.visualization.arrayToDataTable({{ json_date|json_encode|raw }});
console.log(data);
let chart = new google.visualization.LineChart(document.getElementById('curve_chart'));
chart.draw(data, classicOptions);
}
</script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script>
function run(strategy) {
const url = setUpQuery(strategy);
fetch(url)
.then(response => response.json())
.then(json => {
google.charts.load('current', {'packages': ['gauge']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Label', 'Value'],
[strategy, json.lighthouseResult.categories.performance.score * 100]
]);
var options = {
width: 800, height: 180,
redFrom: 0, redTo: 49,
yellowFrom: 50, yellowTo: 89,
greenFrom: 90, greenTo: 100,
minorTicks: 5
};
var chart = new google.visualization.Gauge(document.getElementById('chart_div_' + strategy));
chart.draw(data, options);
}
if (json.loadingExperience.metrics) {
var fieldMetrics = [
{'metric': 'FIRST_CONTENTFUL_PAINT_MS', 'id': 'field-data-fcp'},
{'metric': 'FIRST_INPUT_DELAY_MS', 'id': 'field-data-fid'},
{'metric': 'LARGEST_CONTENTFUL_PAINT_MS', 'id': 'field-data-lcp'},
{'metric': 'CUMULATIVE_LAYOUT_SHIFT_SCORE', 'id': 'field-data-cls'}
];
var badgeConfig = {'FAST': 'badge-success', 'AVERAGE': 'badge-warning', 'SLOW': 'badge-danger'};
var scoreLabels = ['良好', '改善が必要', '低速'];
fieldMetrics.forEach(function (m) {
var id = '#' + strategy + '-' + m.id;
var data = json.loadingExperience.metrics[m.metric];
data.distributions.sort(function (d) {
return d.min
});
$(id + ' span.badge').addClass(badgeConfig[data.category]);
data.distributions.forEach(function (d, i) {
var proportionLabel = Math.round(d.proportion * 100) + '%';
var message = 'このページの読み込みの' + proportionLabel + 'は「' + scoreLabels[i] + '」でした。('
if (d.min && d.max) {
message += (d.min + ' 〜 ' + d.max);
} else if (d.min) {
message += ('> ' + d.min);
} else if (d.max) {
message += ('< ' + d.max);
}
if (m.metric.match(/MS$/)) {
message += ' ms'
}
message += ')';
$(id + ' div.progress-bar:eq(' + i + ')')
.css('width', d.proportion * 100 + '%')
.text(proportionLabel)
.attr({'data-tooltip': 'true', 'data-original-title': message})
});
});
} else {
$('.' + strategy + '-field')
.html('<div class="col-12 m-2"><div class="alert alert-warning" role="alert">このページの実際の速度データが十分にありません。</div></div>');
}
function badgeClass(score) {
if (score <= 0.49) {
return 'badge-danger';
} else if (score <= 0.89) {
return 'badge-warning';
} else {
return 'badge-success';
}
}
$('#' + strategy + '-lab-fcp-value').text(json.lighthouseResult.audits["first-contentful-paint"].displayValue);
$('#' + strategy + '-lab-fcp-badge').addClass(badgeClass(json.lighthouseResult.audits["first-contentful-paint"].score));
$('#' + strategy + '-lab-tti-value').text(json.lighthouseResult.audits["interactive"].displayValue);
$('#' + strategy + '-lab-tti-badge').addClass(badgeClass(json.lighthouseResult.audits["interactive"].score));
$('#' + strategy + '-lab-speed-value').text(json.lighthouseResult.audits["speed-index"].displayValue);
$('#' + strategy + '-lab-speed-badge').addClass(badgeClass(json.lighthouseResult.audits["speed-index"].score));
$('#' + strategy + '-lab-tbt-value').text(json.lighthouseResult.audits["total-blocking-time"].displayValue);
$('#' + strategy + '-lab-tbt-badge').addClass(badgeClass(json.lighthouseResult.audits["total-blocking-time"].score));
$('#' + strategy + '-lab-lcp-value').text(json.lighthouseResult.audits["largest-contentful-paint"].displayValue);
$('#' + strategy + '-lab-lcp-badge').addClass(badgeClass(json.lighthouseResult.audits["largest-contentful-paint"].score));
$('#' + strategy + '-lab-cls-value').text(json.lighthouseResult.audits["cumulative-layout-shift"].displayValue);
$('#' + strategy + '-lab-cls-badge').addClass(badgeClass(json.lighthouseResult.audits["cumulative-layout-shift"].score));
}).then(function() {
$('.' + strategy + '-init').addClass('d-none');
$('.' + strategy + '-loaded').removeClass('d-none');
});
}
function setUpQuery(strategy) {
const api = 'https://www.googleapis.com/pagespeedonline/v5/runPagespeed';
const parameters = {
url: encodeURIComponent('{{ ownedSiteUrl }}'),
strategy: strategy
};
let query = `${api}?`;
for (key in parameters) {
query += `${key}=${parameters[key]}&`;
}
return query;
}
run('desktop');
run('mobile');
$('[data-toggle="tooltip"]').tooltip();
</script>
{% endblock javascript %}
{% block main %}
<div class="c-contentsArea__cols">
<div class="c-contentsArea__primaryCol">
<!-- パフォーマンススコア-START -->
<div class="card rounded border-0 mb-4">
<div class="card-header">
<div class="row">
<div class="col-8">
<h3>パフォーマンス</h3>
</div>
<div class="col-4 text-end">
<a href="https://developers.google.com/web/tools/lighthouse#devtools" target="_blank">
<button type="button" class="btn btn-ec-regular">
<img style="width: 20px;" src="{{ asset('SiteKit42/assets/lighthouse-logo.svg', 'plugin') }}" alt="google-pagespeed-insights image"> {{ 'Lighthouseのすべてのレポートを確認する'|trans }}
</button>
</a>
</div>
</div>
</div>
<div class="collapse show ec-cardCollapse" id="basicConfig">
<div class="card-body">
<div class="row">
<div class="col-6 border-end">
<div id="chart_div_desktop" class="d-flex align-items-center justify-content-center" style="height: 240px;">
<img src="{{ asset('assets/img/loading.gif', 'admin') }}" alt="loading">
</div>
</div>
<div class="col-6">
<div id="chart_div_mobile" class="d-flex align-items-center justify-content-center" style="height: 240px;">
<img src="{{ asset('assets/img/loading.gif', 'admin') }}" alt="loading">
</div>
</div>
</div>
<div class="pb-4">
<h5>フィールドデータ</h5>
<div class="row">
<div class="col-6 border-end">
<div class="row desktop-init">
<div class="col-12">
<div class="d-flex align-items-center justify-content-center" style="height: 100px;">
<img src="{{ asset('assets/img/loading.gif', 'admin') }}" alt="loading">
</div>
</div>
</div>
<div class="row d-none desktop-loaded desktop-field">
<div class="col-6 py-1" id="desktop-field-data-fcp">
<div class="mb-2"><span class="badge"> </span><span class="fw-bold"> First Contentful Paint(FCP)</span></div>
<div>
<div class="progress" style="height: 18px;">
<div class="progress-bar bg-success" role="progressbar" aria-valuenow="15" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip"></div>
<div class="progress-bar bg-warning" role="progressbar" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip"></div>
<div class="progress-bar bg-danger" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip"></div>
</div>
</div>
</div>
<div class="col-6 py-1" id="desktop-field-data-fid">
<div class="mb-2"><span class="badge"> </span><span class="fw-bold"> First Input Delay(FID)</span></div>
<div>
<div class="progress" style="height: 18px;">
<div class="progress-bar bg-success" role="progressbar" aria-valuenow="15" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip"></div>
<div class="progress-bar bg-warning" role="progressbar" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip"></div>
<div class="progress-bar bg-danger" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip"></div>
</div>
</div>
</div>
<div class="col-6 py-1" id="desktop-field-data-lcp">
<div class="mb-2"><span class="badge"> </span><span class="fw-bold"> Largest Contentful Paint(LCP)</span></div>
<div>
<div class="progress" style="height: 18px;">
<div class="progress-bar bg-success" role="progressbar" aria-valuenow="15" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip"></div>
<div class="progress-bar bg-warning" role="progressbar" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip"></div>
<div class="progress-bar bg-danger" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip"></div>
</div>
</div>
</div>
<div class="col-6 py-1" id="desktop-field-data-cls">
<div class="mb-2"><span class="badge"> </span><span class="fw-bold"> Cumulative Layout Shift(CLS)</span></div>
<div>
<div class="progress" style="height: 18px;">
<div class="progress-bar bg-success" role="progressbar" aria-valuenow="15" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip"></div>
<div class="progress-bar bg-warning" role="progressbar" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip"></div>
<div class="progress-bar bg-danger" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip"></div>
</div>
</div>
</div>
</div>
</div>
<div class="col-6">
<div class="row mobile-init">
<div class="col-12">
<div class="d-flex align-items-center justify-content-center" style="height: 100px;">
<img src="{{ asset('assets/img/loading.gif', 'admin') }}" alt="loading">
</div>
</div>
</div>
<div class="row d-none mobile-loaded mobile-field">
<div class="col-6 py-1" id="mobile-field-data-fcp">
<div class="mb-2"><span class="badge"> </span><span class="fw-bold"> First Contentful Paint(FCP)</span></div>
<div>
<div class="progress" style="height: 18px;">
<div class="progress-bar bg-success" role="progressbar" aria-valuenow="15" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip"></div>
<div class="progress-bar bg-warning" role="progressbar" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip"></div>
<div class="progress-bar bg-danger" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip"></div>
</div>
</div>
</div>
<div class="col-6 py-1" id="mobile-field-data-fid">
<div class="mb-2"><span class="badge"> </span><span class="fw-bold"> First Input Delay(FID)</span></div>
<div>
<div class="progress" style="height: 18px;">
<div class="progress-bar bg-success" role="progressbar" aria-valuenow="15" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip"></div>
<div class="progress-bar bg-warning" role="progressbar" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip"></div>
<div class="progress-bar bg-danger" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip"></div>
</div>
</div>
</div>
<div class="col-6 py-1" id="mobile-field-data-lcp">
<div class="mb-2"><span class="badge"> </span><span class="fw-bold"> Largest Contentful Paint(LCP)</span></div>
<div>
<div class="progress" style="height: 18px;">
<div class="progress-bar bg-success" role="progressbar" aria-valuenow="15" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip"></div>
<div class="progress-bar bg-warning" role="progressbar" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip"></div>
<div class="progress-bar bg-danger" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip"></div>
</div>
</div>
</div>
<div class="col-6 py-1" id="mobile-field-data-cls">
<div class="mb-2"><span class="badge"> </span><span class="fw-bold"> Cumulative Layout Shift(CLS)</span></div>
<div>
<div class="progress" style="height: 18px;">
<div class="progress-bar bg-success" role="progressbar" aria-valuenow="15" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip"></div>
<div class="progress-bar bg-warning" role="progressbar" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip"></div>
<div class="progress-bar bg-danger" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<h5>ラボデータ</h5>
<div class="row">
<div class="col-6 border-end desktop-init">
<div class="d-flex align-items-center justify-content-center" style="height: 80px;">
<img src="{{ asset('assets/img/loading.gif', 'admin') }}" alt="loading">
</div>
</div>
<div class="col-6 border-end d-none desktop-loaded">
<div class="row">
<div class="col-4">
<span class="badge" id="desktop-lab-fcp-badge"> </span><span class="fw-bold"> First Contentful Paint</span>
</div>
<div class="col-2 text-end" id="desktop-lab-fcp-value"></div>
<div class="col-4">
<span class="badge" id="desktop-lab-tti-badge"> </span><span class="fw-bold"> Time to Interactive</span>
</div>
<div class="col-2 text-end" id="desktop-lab-tti-value"></div>
<div class="col-4">
<span class="badge" id="desktop-lab-speed-badge"> </span><span class="fw-bold"> Speed Index</span>
</div>
<div class="col-2 text-end" id="desktop-lab-speed-value"></div>
<div class="col-4">
<span class="badge" id="desktop-lab-tbt-badge"> </span><span class="fw-bold"> Total Blocking Time</span>
</div>
<div class="col-2 text-end" id="desktop-lab-tbt-value"></div>
<div class="col-4">
<span class="badge" id="desktop-lab-lcp-badge"> </span><span class="fw-bold"> Largest Contentful Paint</span>
</div>
<div class="col-2 text-end" id="desktop-lab-lcp-value"></div>
<div class="col-4">
<span class="badge" id="desktop-lab-cls-badge"> </span><span class="fw-bold"> Cumulative Layout Shift</span>
</div>
<div class="col-2 text-end" id="desktop-lab-cls-value"></div>
</div>
</div>
<div class="col-6 border-end mobile-init">
<div class="d-flex align-items-center justify-content-center" style="height: 80px;">
<img src="{{ asset('assets/img/loading.gif', 'admin') }}" alt="loading">
</div>
</div>
<div class="col-6">
<div class="row d-none mobile-loaded">
<div class="col-4">
<span class="badge" id="mobile-lab-fcp-badge"> </span><span class="fw-bold"> First Contentful Paint</span>
</div>
<div class="col-2 text-end" id="mobile-lab-fcp-value"></div>
<div class="col-4">
<span class="badge" id="mobile-lab-tti-badge"> </span><span class="fw-bold"> Time to Interactive</span>
</div>
<div class="col-2 text-end" id="mobile-lab-tti-value"></div>
<div class="col-4">
<span class="badge" id="mobile-lab-speed-badge"> </span><span class="fw-bold"> Speed Index</span>
</div>
<div class="col-2 text-end" id="mobile-lab-speed-value"></div>
<div class="col-4">
<span class="badge" id="mobile-lab-tbt-badge"> </span><span class="fw-bold"> Total Blocking Time</span>
</div>
<div class="col-2 text-end" id="mobile-lab-tbt-value"></div>
<div class="col-4">
<span class="badge" id="mobile-lab-lcp-badge"> </span><span class="fw-bold"> Largest Contentful Paint</span>
</div>
<div class="col-2 text-end" id="mobile-lab-lcp-value"></div>
<div class="col-4">
<span class="badge" id="mobile-lab-cls-badge"> </span><span class="fw-bold"> Cumulative Layout Shift</span>
</div>
<div class="col-2 text-end" id="mobile-lab-cls-value"></div>
</div>
</div>
</div>
<div class="pt-5">
<span style="font-size: 18px;"><img style="width: 40px;" src="{{ asset('SiteKit42/assets/lighthouse-logo.svg', 'plugin') }}" alt="google-search-console image"> Powered by <a href="https://developers.google.com/web/tools/lighthouse" target="_blank">Lighthouse</a> (v.6.3.0)</span>
</div>
</div>
</div>
</div>
</div>
<!-- パフォーマンススコア-END -->
<!-- アクセス推移-START -->
<div class="card rounded border-0 mb-4">
<div class="card-header">
<div class="row">
<div class="col-8">
<h3>アクセス推移(過去28日間)</h3>
</div>
<div class="col-4 text-end">
<a href="https://search.google.com/search-console?utm_source=about-page&resource_id={{ ownedSiteUrl }}"
target="_blank">
<button type="button" class="btn btn-ec-regular">
<img style="width: 18px;"
src="{{ asset('SiteKit42/assets/google-search-console.svg', 'plugin') }}"
alt="google-search-console image"> {{ 'Google Search Consoleへ'|trans }}
</button>
</a>
</div>
</div>
</div>
<div class="collapse show ec-cardCollapse" id="basicConfig">
<div class="card-body">
<div class="row">
<div class="col-12">
<div id="curve_chart"></div>
</div>
</div>
</div>
</div>
</div>
<!-- アクセス推移-END -->
<!-- キーワード情報-START -->
<div class="card rounded border-0 mb-4">
<div class="card-header">
<div class="row">
<div class="col-8">
<h3>キーワード情報(過去28日間)</h3>
</div>
<div class="col-4 text-end">
<a href="https://search.google.com/search-console?utm_source=about-page&resource_id={{ ownedSiteUrl }}"
target="_blank">
<button type="button" class="btn btn-ec-regular">
<img style="width: 18px;"
src="{{ asset('SiteKit42/assets/google-search-console.svg', 'plugin') }}"
alt="google-search-console image"> {{ 'Google Search Consoleへ'|trans }}
</button>
</a>
</div>
</div>
</div>
<div class="collapse show ec-cardCollapse" id="basicConfig">
<div class="card-body">
<div class="row">
<div class="col-12">
{% if json_query.rows %}
<table class="table table-sm table-striped table-bordered">
<colgroup>
<col>
<col style="width: 10em;">
<col style="width: 10em;">
<col style="width: 10em;">
<col style="width: 10em;">
</colgroup>
<thead>
<tr>
<th class="border-top-0 py-2 text-start">キーワード</th>
<th class="border-top-0 py-2 text-start">クリック数</th>
<th class="border-top-0 py-2 text-start">インプレッション</th>
<th class="border-top-0 py-2 text-start">クリックレート</th>
<th class="border-top-0 py-2 text-start">平均表示ランク</th>
</tr>
</thead>
<tbody>
{% for row in json_query.rows %}
<tr>
<td class="align-middle text-start ps-3">{{ row.keys[0] }}</td>
<td class="align-middle text-end ps-3">{{ row.clicks|number_format }}</td>
<td class="align-middle text-end ps-3">{{ row.impressions|number_format }}</td>
<td class="align-middle text-end ps-3">{{ row.ctr }}</td>
<td class="align-middle text-end ps-3">{{ row.position }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<div class="alert alert-warning" role="alert">データがまだありません。</div>
{% endif %}
</div>
</div>
</div>
</div>
</div>
<!-- キーワード情報-END -->
<!-- ページ情報-START -->
<div class="card rounded border-0 mb-4">
<div class="card-header">
<div class="row">
<div class="col-8">
<h3>ページ情報(過去28日間)</h3>
</div>
<div class="col-4 text-end">
<a href="https://search.google.com/search-console?utm_source=about-page&resource_id={{ ownedSiteUrl }}"
target="_blank">
<button type="button" class="btn btn-ec-regular">
<img style="width: 18px;"
src="{{ asset('SiteKit42/assets/google-search-console.svg', 'plugin') }}"
alt="google-search-console image"> {{ 'Google Search Consoleへ'|trans }}
</button>
</a>
</div>
</div>
</div>
<div class="collapse show ec-cardCollapse" id="basicConfig">
<div class="card-body">
<div class="row">
<div class="col-12">
{% if json_page.rows %}
<table class="table table-sm table-striped table-bordered">
<colgroup>
<col>
<col style="width: 10em;">
<col style="width: 10em;">
<col style="width: 10em;">
<col style="width: 10em;">
</colgroup>
<thead>
<tr>
<th class="border-top-0 py-2 text-start">ページ</th>
<th class="border-top-0 py-2 text-start">クリック数</th>
<th class="border-top-0 py-2 text-start">インプレッション</th>
<th class="border-top-0 py-2 text-start">クリックレート</th>
<th class="border-top-0 py-2 text-start">平均表示ランク</th>
</tr>
</thead>
<tbody>
{% for row in json_page.rows %}
<tr>
<td class="align-middle text-start ps-3">{{ row.keys[0] }}</td>
<td class="align-middle text-end ps-3">{{ row.clicks|number_format }}</td>
<td class="align-middle text-end ps-3">{{ row.impressions|number_format }}</td>
<td class="align-middle text-end ps-3">{{ row.ctr }}</td>
<td class="align-middle text-end ps-3">{{ row.position }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<div class="alert alert-warning" role="alert">データがまだありません。</div>
{% endif %}
</div>
</div>
</div>
</div>
</div>
<!-- ページ情報-END -->
</div>
</div>
{% endblock %}