Google Analytics draw chart with ga calls -


i trying draw chart via google's visualization line chart. want line chart based on google analytic site stats. how this?

script type="text/javascript">   google.load("visualization", "1", {packages:["linechart"]});   google.setonloadcallback(drawchart);   function drawchart() {     var data = google.visualization.arraytodatatable([       ['date', 'traffic', 'ecpm'],       ['2004',  i.e ga:pageviews stats...,      1.25],       ['2005',  1170,      5.2],       ['2006',  660,       7.5],       ['2007',  1030,      4.3]     ]);      var chart = new google.visualization.linechart(document.getelementbyid('chart_div'));     chart.draw(data, {width: 400, height: 240, legend: 'bottom', title: 'publisher stats'});   } </script> 

how this? have add visualization chart pull data google analytic? display on chart.

thank you

you should check out embed api, created purpose.

here's example code might queries google analytics , renders google chart:

var datachart = new gapi.analytics.googlecharts.datachart({   query: {     ids: 'ga:xxxx',     metrics: 'ga:sessions',     dimensions: 'ga:date',     'start-date': '30daysago',     'end-date': 'yesterday'   },   chart: {     container: 'chart-container',     type: 'line'   } });  datachart.execute(); 

and site has great demos of embed api in action: https://ga-dev-tools.appspot.com/embed-api/


Comments