Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mrpatrick
Created May 10, 2012 21:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mrpatrick/2655886 to your computer and use it in GitHub Desktop.
Save mrpatrick/2655886 to your computer and use it in GitHub Desktop.
Google Analytics Easy Dashboard Javascript Library demo
<!DOCTYPE>
<html>
<head><title>GA Dash Demo</title></head>
<body onload="chart1.render();" >
<!-- Add Google Analytics authorization button -->
<button id="authorize-button" style="visibility: hidden">
Authorize Analytics</button>
<!-- Div element where the Line Chart will be placed -->
<div id='line-chart-example'></div>
<!-- Load all Google JS libraries -->
<script src="https://www.google.com/jsapi"></script>
<script src="assets/gadash-1.0.js"></script>
<script src="https://apis.google.com/js/client.js?onload=gadashInit"></script>
<script>
// Configure these parameters before you start.
var API_KEY = 'xxx';
var CLIENT_ID = 'xxx';
var TABLE_ID = 'ga:xxx';
// Format of table ID is ga:xxx where xxx is the profile ID.
gadash.configKeys({
'apiKey': API_KEY,
'clientId': CLIENT_ID
});
// Create a new Chart that queries visitors for the last 30 days and plots
// visualizes in a line chart.
var chart1 = new gadash.Chart({
'type': 'LineChart',
'divContainer': 'line-chart-example',
'last-n-days':30,
'query': {
'ids': TABLE_ID,
'metrics': 'ga:visitors',
'dimensions': 'ga:date'
},
'chartOptions': {
height:600,
title: 'Visits in January 2011',
hAxis: {title:'Date'},
vAxis: {title:'Visits'},
curveType: 'function'
}
});
</script>
</body>
</html>
@tlaverdure
Copy link

Fro some reason this is not working for me in Firefox nor Safari...But it works in Chrome? Any suggestions?

@mrpatrick
Copy link
Author

Weird - it seems to work in both FF (12.0) and Safari (5.15) for me - however, I did notice it took a few seconds longer to load in safari. Are you getting any errors in firebug?

@tlaverdure
Copy link

Needed to update my browser. That was the culprit. Thanks

@tlaverdure
Copy link

Hey would you know how to use this library to get data without the chart?

@mrpatrick
Copy link
Author

@tlaverdure - I think you'll have to use the Core Reporting API if you want access to the actual data rather than a chart (you could also use the Table chart if you'd rather a spreadsheet-rendered version of the data: 'type':'Table'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment