上一篇如下圖我們用google API把數字都匯出了,我們是用官方的code稍作改寫而已,接下來就是自訂視覺化的部分了
Hello Analytics Reporting API V4
| demotable |
上一篇如下圖我們用google API把數字都匯出了,我們是用官方的code稍作改寫而已,接下來就是自訂視覺化的部分了
| demotable |
前置:申請一個Blogger_如果你有自己的網址可以跳過這步驟,這是為了後續發布的限制













<meta name="google-signin-client_id" content="用戶端ID">
<!--等於後面要換成用戶端ID剛剛新增的-->
<meta name="google-signin-scope" content="https://www.googleapis.com/auth/analytics.readonly">
<h1>Hello Analytics Reporting API V4</h1>
<!-- The Sign-in button. This will run `queryReports()` on success. -->
<p class="g-signin2" data-onsuccess="queryReports"></p>
<!-- The API response will be printed here. -->
<textarea cols="80" rows="20" id="query-output"></textarea>
<script>
// VIEW_ID要填GA資料檢視層的id
var VIEW_ID = 'GA資料檢視層的ID';
// Query the API and print the results to the page.
function queryReports() {
gapi.client.request({
path: '/v4/reports:batchGet',
root: 'https://analyticsreporting.googleapis.com/',
method: 'POST',
body: {
reportRequests: [
{
viewId: VIEW_ID,
dateRanges: [
{
startDate: '7daysAgo',
endDate: 'today'
}
],
metrics: [
{
expression: 'ga:sessions'
}
]
}
]
}
}).then(displayResults, console.error.bind(console));
}
function displayResults(response) {
var formattedJson = JSON.stringify(response.result, null, 2);
document.getElementById('query-output').value = formattedJson;
}
</script>
<!-- Load the JavaScript API client and Sign-in library. -->
<script src="https://apis.google.com/js/client:platform.js"></script>
登入以後顯示