将Google AnalyticsembeddedAPI图导出为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中导出图表的方式并不像在可视化API中那样。 您可以从Google Analytics报告API中导出数据,使用另一个库(如Google Visualization API )将其导出并导出,或者查看帮助截取HTML2canvas等工具 。