Hi Kieran,
Service account
Using server-side authorization using the Google Python Client API, you can use this demo to access Google Analytics data and charts for each user without logging in .
oAuth for Google APP
Another way is to use oAuth. But in this case, you need to pay for a Google Apps account to run Google Apps . You can read here how to combine applications and oAuth for access without login.
I added here the working code of the new (2016) beta version of the Google Client PHP client for anonymous access using json - including amChart.
In addition, the process of updating json credential files can be automated - this is not done in this code example. ClientLogin current may last 2 weeks from the release date, but this limit is service specific and may be shorter. You can change the lifespan in Google_AssertionCredentials.php (24), although this is a security risk (for your money - if someone calls the site it will automatically end with the allowable amount of duty free trading)
class Google_AssertionCredentials { const MAX_TOKEN_LIFETIME_SECS = 360000;
To make autoload.php work correctly, you need to install Client PHP API resources using composer.phar in htdocs (Apache) or wwwroot (IIS) and put this code in the vendor folder.
I did not use dataLoader and commented on it, for amChart stucks in my environment at boot time. Therefore, I used a dataprovider that works reliably.
/* "dataLoader": { "url": "data.php", "format": "json" }, */ <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" /> <title>Gimba - Google Analytics - GimbaChartAll</title> <script src="https://www.amcharts.com/lib/3/amcharts.js"></script> <script src="https://www.amcharts.com/lib/3/serial.js"></script> <script src="https://www.amcharts.com/lib/3/plugins/dataloader/dataloader.min.js"></script> <style> body, html { font-family: Verdana; font-size: 10px; } #chartdiv { width: 1100px; height: 700px; margin-left:auto; margin-right:auto; } </style> <script> var dataJS = <?php echo dataGA(); ?>; var chart = AmCharts.makeChart("chartdiv", { "type": "serial", "theme": "light", /* "dataLoader": { "url": "data.php", "format": "json" }, */ "dataProvider": dataJS , "categoryField": "country", "categoryAxis": { "gridColor": "#0000FF", "gridAlpha": 0.07, "title": "Country" }, "creditsPosition": "top-right", "categoryField": "country", "categoryAxis": { "gridAlpha": 0.07, "gridPosition": "start", "tickPosition": "start", "title": "Country" }, "valueAxes": [ { "id": "v1", "gridAlpha": 0.1, "axisColor": "#0000ff", "title": "Users/Sessions" }, { "id": "v2", "gridAlpha": 0, "axisColor": "#0000ff", "position": "right", "title": "Page views" } ], "graphs": [ { "startDuration": 3, "type": "column", "title": "Sessions", "valueField": "sessions", "fillColors": "#0000ff" , "lineAlpha": 0, "fillAlphas": 0.6 }, { "type": "column", "title": "Users", "valueField": "users", "fillColors": "#0000ff" , "lineAlpha": 0, "fillAlphas": 0.2 }, { "type": "line", "valueAxis": "v2", "title": "Page views", "valueField": "pageviews", "lineColor": "#0000ff" , "lineThickness": 1, "bullet": "round" } ], "legend": {} } ); </script> </head> <body> <div id="chartdiv"></div> </body> </html> <?php
Sincerely, Axel Arnold Bangert - Herzogenrath 2016