The JSON array provided here contains all the metrics and dimensions available from the Google Analytics API v3:
To create a table showing the number of dimensions and metrics, you can use the following code:
var results = new Array();
for (var j = 0; j < output.items.length; j++) {
var key = output.items[j].attributes.type.toString();
if (!results[key]) {
results[key]=1
} else {
results[key]=results[key] + 1;
}
}
The outcome is: [DIMENSION: 244, METRIC: 206]
In addition to this data, it's also possible to determine the status of each dimension or metric as public, deprecated, or any other classification that may be assigned by Google. To achieve this, you can use the following code:
var statusDimensions = new Array();
for (var j=0; j<output.items.length; j++) {
var key = output.items[j].attributes.type.toString();
var subKey = output.items[j].attributes.status.toString();
if (key != "METRIC" && !statusDimensions[subKey]) {
statusDimensions[subKey] = 1
} else {
statusDimensions[subKey] = statusDimensions[subKey] + 1;
}
}
However, the result currently shows: [PUBLIC: 414, DEPRECATED: 36]
, indicating an unexpected behavior in the evaluation of the condition key != "METRIC"
.
- What could be causing this issue?
- Is there a way to combine both type and status information in a single loop and array?