1
votes

It seems a bit redundant in places. Could it not just be excluded? I'm wondering from an API design point of view.

For example, the ViewId is "is in the format of ga:XXXX, where XXXX" at https://developers.google.com/analytics/devguides/reporting/core/v4/migration#view_ids

The metrics expression is "ga:users" at https://developers.google.com/analytics/devguides/reporting/core/v4/migration#introduction

eg.

POST https://analyticsreporting.googleapis.com/v4/reports:batchGet
{
  "reportRequests":[
  {
    "viewId":"XXXX",
    "dateRanges":[
    {
      "startDate":"2015-11-01",
      "endDate":"2015-11-06"
    }],
    "metrics":[
    {
      "expression":"ga:users"
    },{
      "expression":"ga:sessions"
    }],
    ...
  }]
}

Same for dimensions, etc.

1
You can use the alias field for metrics if you truly want to ditch the ga: prefix, but the alias field really comes in handy if you have complicated metricExpression. But Eric is right the prefix is to distinguish various API dimensions with the same name.Matt

1 Answers

4
votes

That's namespacing to distinguish names for metrics and dimension from similar names in other APIs. For example both the Core Reporting API and the Realtime API have a dimension "medium", and you can easily see which API is used when your see ga:medium versus rt:medium, "rt" being the prefix that indicates Realtime API queries.