Skip to content

Commit 40dc7dc

Browse files
author
Julia
committed
2 parents 36ea9ff + 51025e4 commit 40dc7dc

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

HelloAnalytics.html

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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

Comments
 (0)