アカウントが最初に認証され、次に Google アナリティクスからクエリ結果を取得するすべてのクエリ機能を実行しました。
結果を以下の表コードに出力します。
//To Get the Profile ID first
function queryCoreReportingApi(profileId) {
updatePage('Querying Core Reporting API.');
gapi.client.analytics.data.ga.get({
'ids': 'ga:' + profileId,
'start-date': lastNDays(14),
'end-date': lastNDays(0),
'dimensions': 'ga:date,ga:year,ga:month,ga:week,ga:day',
'metrics': 'ga:visitors'
}).execute(handleCoreReportingResults);
}
//To Show the Result
function handleCoreReportingResults(response) {
if (!response.code) {
if (response.rows && response.rows.length) {
var output = [];
// Profile Name.
output.push('Profile Name: ', response.profileInfo.profileName, '<br>');
var table = ['<table>'];
// Put headers in table.
table.push('<tr>');
for (var i = 0, header; header = response.columnHeaders[i]; ++i) {
table.push('<th>', header.name, '</th>');
}
table.push('</tr>');
// Put cells in table.
for (var i = 0, row; row = response.rows[i]; ++i) {
table.push('<tr><td>', row.join('</td><td>'), '</td></tr>');
}
table.push('</table>');
output.push(table.join(''));
outputToPage(output.join(''));
} else {
outputToPage('No results found.');
}
} else {
updatePage('There was an error querying core reporting API: ' +
response.message);
}
}
function outputToPage(output) {
document.getElementById('output').innerHTML = output;
}
function updatePage(output) {
document.getElementById('output').innerHTML += '<br>' + output;
}
問題は、返された結果を Google チャート (棒グラフ - 円グラフなど) に表示する方法です。私は googlecharts.js を使用するのにうんざりしていましたが、ユーザーがどのように統合するかはわかりませんでした。誰でも助けてください