导出 Google 分析将 API 图表嵌入到 PNG & Excel
Export Google Analytics Embed API diagram to PNG & Excel
我需要将我的 Google Analytics Embed API 图表导出为 PNG(或 JPG)和 Excel。
我的图表工作正常,没有任何问题或错误,我只想导出我的数据。
我当前的代码是:
<!DOCTYPE html>
<html>
<head>
<title>Embed API Demo</title>
</head>
<body>
<section id="auth-button"></section>
<h2>Visits</h2>
<fieldset>
<legend>Usersers & Sessions over past week</legend>
<section id="timelineWeek"></section>
</fieldset>
<script>
(function (w, d, s, g, js, fjs) {
g = w.gapi || (w.gapi = {}); g.analytics = { q: [], ready: function (cb) { this.q.push(cb) } };
js = d.createElement(s); fjs = d.getElementsByTagName(s)[0];
js.src = 'https://apis.google.com/js/platform.js';
fjs.parentNode.insertBefore(js, fjs); js.onload = function () { g.load('analytics') };
}(window, document, 'script'));
</script>
<script>
function BuildOptions(hAxis) {
return {
width: (window.innerWidth - 60), fontSize: 12,
legend: { position: 'top', alignment: 'center', textStyle: { fontSize: 16 } },
series: { 0: { color: 'red' }, 1: { color: 'orange' } },
hAxis: { title: hAxis }
};
}
gapi.analytics.ready(function () {
var GID = { query: { ids: 'ga:MYACCOUNTPROPERTY' } };
var CLIENT_ID = 'MYSSECRETKEY';
gapi.analytics.auth.authorize({
container: 'auth-button',
clientid: CLIENT_ID,
});
var timelineToday = new gapi.analytics.googleCharts.DataChart({
reportType: 'ga',
query: {
'dimensions': 'ga:hour',
'metrics': 'ga:users,ga:sessions',
'start-date': 'today',
'end-date': 'today',
},,
chart: {
type: 'LINE',
container: 'timelineWeek',
options: BuildOptions('Date')
}
});
gapi.analytics.auth.on('success', function (response) {
timelineWeek.set(GID).execute();
});
});
</script>
</body>
</html>
这也是我的图表快照:
没有从 Google Analytics Embed API like there is in the visualization API. You can either export the data from the Analytics Reporting API, render it with another library (like the Google Visualization API) and export it, or look into tools that help take screenshots like html2canvas.
中导出图表的本机方法
我需要将我的 Google Analytics Embed API 图表导出为 PNG(或 JPG)和 Excel。
我的图表工作正常,没有任何问题或错误,我只想导出我的数据。
我当前的代码是:
<!DOCTYPE html>
<html>
<head>
<title>Embed API Demo</title>
</head>
<body>
<section id="auth-button"></section>
<h2>Visits</h2>
<fieldset>
<legend>Usersers & Sessions over past week</legend>
<section id="timelineWeek"></section>
</fieldset>
<script>
(function (w, d, s, g, js, fjs) {
g = w.gapi || (w.gapi = {}); g.analytics = { q: [], ready: function (cb) { this.q.push(cb) } };
js = d.createElement(s); fjs = d.getElementsByTagName(s)[0];
js.src = 'https://apis.google.com/js/platform.js';
fjs.parentNode.insertBefore(js, fjs); js.onload = function () { g.load('analytics') };
}(window, document, 'script'));
</script>
<script>
function BuildOptions(hAxis) {
return {
width: (window.innerWidth - 60), fontSize: 12,
legend: { position: 'top', alignment: 'center', textStyle: { fontSize: 16 } },
series: { 0: { color: 'red' }, 1: { color: 'orange' } },
hAxis: { title: hAxis }
};
}
gapi.analytics.ready(function () {
var GID = { query: { ids: 'ga:MYACCOUNTPROPERTY' } };
var CLIENT_ID = 'MYSSECRETKEY';
gapi.analytics.auth.authorize({
container: 'auth-button',
clientid: CLIENT_ID,
});
var timelineToday = new gapi.analytics.googleCharts.DataChart({
reportType: 'ga',
query: {
'dimensions': 'ga:hour',
'metrics': 'ga:users,ga:sessions',
'start-date': 'today',
'end-date': 'today',
},,
chart: {
type: 'LINE',
container: 'timelineWeek',
options: BuildOptions('Date')
}
});
gapi.analytics.auth.on('success', function (response) {
timelineWeek.set(GID).execute();
});
});
</script>
</body>
</html>
这也是我的图表快照:
没有从 Google Analytics Embed API like there is in the visualization API. You can either export the data from the Analytics Reporting API, render it with another library (like the Google Visualization API) and export it, or look into tools that help take screenshots like html2canvas.
中导出图表的本机方法