Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using and querying Custom Dimensions in Google Analytics API

I am attempting to query my Analytics (Universal) to receive a list of metrics sorted by a custom dimension.

In July, the Google Analytics API blog announced:

"Developers can use custom dimensions to send unique IDs into Google Analytics, and then use the core reporting API to retrieve these IDs along with other Google Analytics data.

For example, your content management system can pass a content ID as a custom dimension using the Google Analytics tracking code. Developers can then use the API to get a list of the most popular content by ID and display the list of most popular content on their website."

Despite this, I have been unable to retrieve any results from my Analytics. My send function is below:

ga('send', 'pageview', {
  'dimension1':'red'
});

Unfortunately, querying GA using a filter of 'ga:dimension1 == red' does not retrieve any results.

gapi.client.analytics.data.ga.get({
  'ids': 'ga:' + "123456",
  'start-date': '2013-11-10',
  'end-date': '2013-11-20',
  'metrics': 'ga:visits',
  'filters': 'ga:dimension1==red'
}).execute(function(r){console.log(r);});

I have also tried using custom segments to retrieve the data, to no avail:

'segment': 'dynamic::ga:dimension1==red'

The data appears in Custom Reports in GA. How can I access it via the API?

like image 843
arami Avatar asked Nov 26 '13 21:11

arami


1 Answers

You need to include a the dimension in the query. Such as 'dimension': 'ga:dimension1', then use your filter 'ga:dimension1==red'. The Query Explorer is very helpful for testing API requests.

like image 118
Blexy Avatar answered Nov 04 '22 11:11

Blexy