Technologies: Google Reporting API V4 and Google Visualization API, combining PHP and Javascript. There are specific reasons we are not able to install and use the Google Client library.
The problem: the Visualization Api is giving me "invalid type Integer" when that is what the type the Google Reporting API is returning. I know that type integer is not supported in the Visualization API,
https://developers.google.com/chart/interactive/docs/reference#DataTable_addColumn
So the question is what is the correct approach to dynamically use the Reporting API headers to construct chart table headers? Do we need to map the data types every time?
In a nutshell: I query for Analytics data and get the following header structure:
[columnHeader] => Array
(
[dimensions] => Array
(
[0] => ga:date
)
[metricHeader] => Array
(
[metricHeaderEntries] => Array
(
[0] => Array
(
[name] => ga:users
[type] => INTEGER
)
[1] => Array
(
[name] => ga:sessions
[type] => INTEGER
)
)
)
)
When I attempt to create columns,
...
$mtype = $headers['metricHeader']['metricHeaderEntries'][0]['type'];
...
$column_object = "{'type':'$mtype','label':'$mname'}";
// produces {'type':'INTEGER','label':'ga:users'}
...
data.addColumn($column_object);
(Firefox) console logs "Invalid type, INTEGER, for column "Users."
I can "cheat" here by hard coding 'number' for type:
$column_object = "{'type':'number','label':'$mname'}";
Which works fine but I shouldn't have to (or am missing something) and presents some challenges in making metrics and dimensions dynamic. "Users" is indeed a number/integer. Can't help feeling it's something I overlooked that would easily map the columns from the data.