Skip to content

Instantly share code, notes, and snippets.

@ptsakyrellis
Created February 11, 2018 19:03
Show Gist options
  • Save ptsakyrellis/7b5d896384025e8555530a3cb5346e59 to your computer and use it in GitHub Desktop.
Save ptsakyrellis/7b5d896384025e8555530a3cb5346e59 to your computer and use it in GitHub Desktop.
Displays a google analytics chart
gapi.analytics.ready(function() {
/**
* Authorize the user with an access token obtained server side.
*/
gapi.analytics.auth.authorize({
'serverAuth': {
'access_token': '{{ token.access_token }}'
}
});
/**
* Creates a new DataChart instance showing sessions over the past 30 days.
* It will be rendered inside an element with the id "chart-1-container".
*/
var dataChart1 = new gapi.analytics.googleCharts.DataChart({
query: {
'ids': 'ga:12345678', // <-- Replace with the ids value for your view.
'start-date': '30daysAgo',
'end-date': 'yesterday',
'metrics': 'ga:sessions,ga:users',
'dimensions': 'ga:date'
},
chart: {
'container': 'chart-1-container',
'type': 'LINE',
'options': {
'width': '100%'
}
}
});
dataChart1.execute();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment