Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to retrive google analytics data and display it on my html page...
I tried using the javascript code but it shows blank page
link where i copied the javascript code
http://ga-dev-tools.appspot.com/embed-api/basic-dashboard/

What I have tried:

I have tried the following javascript code, but shows blank page...

<script>
(function(w,d,s,g,js,fs){
g=w.gapi||(w.gapi={});g.analytics={q:[],ready:function(f){this.q.push(f);}};
js=d.createElement(s);fs=d.getElementsByTagName(s)[0];
js.src='https://apis.google.com/js/platform.js';
fs.parentNode.insertBefore(js,fs);js.onload=function(){g.load('analytics');};
}(window,document,'script'));
</script>


<script>

gapi.analytics.ready(function() {

gapi.analytics.auth.authorize({
container: 'embed-api-auth-container',
clientid: 'REPLACE WITH YOUR CLIENT ID'
});


var viewSelector = new gapi.analytics.ViewSelector({
container: 'view-selector-container'
});

// Render the view selector to the page.
viewSelector.execute();


var dataChart = new gapi.analytics.googleCharts.DataChart({
query: {
metrics: 'ga:sessions',
dimensions: 'ga:date',
'start-date': '30daysAgo',
'end-date': 'yesterday'
},
chart: {
container: 'chart-container',
type: 'LINE',
options: {
width: '100%'
}
}
});


viewSelector.on('change', function(ids) {
dataChart.set({query: {ids: ids}}).execute();
});

});
</script>




Posted
Updated 1-May-16 0:29am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900