|
| 1 | +<script> |
| 2 | +(function(w,d,s,g,js,fs){ |
| 3 | + g=w.gapi||(w.gapi={});g.analytics={q:[],ready:function(f){this.q.push(f);}}; |
| 4 | + js=d.createElement(s);fs=d.getElementsByTagName(s)[0]; |
| 5 | + js.src='https://apis.google.com/js/platform.js'; |
| 6 | + fs.parentNode.insertBefore(js,fs);js.onload=function(){g.load('analytics');}; |
| 7 | +}(window,document,'script')); |
| 8 | +</script> |
| 9 | + |
| 10 | +<div id="embed-api-auth-container"></div> |
| 11 | +<div id="chart-container"></div> |
| 12 | +<div id="view-selector-container"></div> |
| 13 | +<script> |
| 14 | + |
| 15 | +gapi.analytics.ready(function() { |
| 16 | + |
| 17 | + /** |
| 18 | + * Authorize the user immediately if the user has already granted access. |
| 19 | + * If no access has been created, render an authorize button inside the |
| 20 | + * element with the ID "embed-api-auth-container". |
| 21 | + */ |
| 22 | + gapi.analytics.auth.authorize({ |
| 23 | + container: 'embed-api-auth-container', |
| 24 | + clientid: '1020428475379-i265lih95a3ips9u6j5c0so8hmpg21kk.apps.googleusercontent.com' |
| 25 | + }); |
| 26 | + |
| 27 | + |
| 28 | + /** |
| 29 | + * Create a new ViewSelector instance to be rendered inside of an |
| 30 | + * element with the id "view-selector-container". |
| 31 | + */ |
| 32 | + var viewSelector = new gapi.analytics.ViewSelector({ |
| 33 | + container: 'view-selector-container' |
| 34 | + }); |
| 35 | + |
| 36 | + // Render the view selector to the page. |
| 37 | + viewSelector.execute(); |
| 38 | + |
| 39 | + |
| 40 | + /** |
| 41 | + * Create a new DataChart instance with the given query parameters |
| 42 | + * and Google chart options. It will be rendered inside an element |
| 43 | + * with the id "chart-container". |
| 44 | + */ |
| 45 | + var dataChart = new gapi.analytics.googleCharts.DataChart({ |
| 46 | + query: { |
| 47 | + metrics: 'ga:sessions', |
| 48 | + dimensions: 'ga:date', |
| 49 | + 'start-date': '30daysAgo', |
| 50 | + 'end-date': 'yesterday' |
| 51 | + }, |
| 52 | + chart: { |
| 53 | + container: 'chart-container', |
| 54 | + type: 'LINE', |
| 55 | + options: { |
| 56 | + width: '100%' |
| 57 | + } |
| 58 | + } |
| 59 | + }); |
| 60 | + |
| 61 | + |
| 62 | + /** |
| 63 | + * Render the dataChart on the page whenever a new view is selected. |
| 64 | + */ |
| 65 | + viewSelector.on('change', function(ids) { |
| 66 | + dataChart.set({query: {ids: ids}}).execute(); |
| 67 | + }); |
| 68 | + |
| 69 | +}); |
| 70 | +</script> |
0 commit comments