albertski
albertski

Reputation: 2622

How to get custom variable info from Google Analytics via API

I have data stored in the Second Dimension Google Analytics Events. The field is called Custom Variable (Value 01).

How can I use the GA api to get the values from Custom Variable (Value 01).

I'm using the GA explorer http://ga-dev-tools.appspot.com/explorer/ and can't figure out how to get the Custom Variable.

I see these options: ga:dimensionXX ga:customVarNameXX ga:customVarValueXX

I tried replacing the xx with 01 but I had no luck. Anyone know how I can get the info for GA via API?

Upvotes: 2

Views: 2041

Answers (2)

albertski
albertski

Reputation: 2622

Thanks to @Blexy. This was my code at the end:

$params = array(
  'metrics' => 'ga:visitors',
   'dimensions' =>      'ga:customVarValue1,ga:eventLabel,ga:deviceCategory,ga:operatingSystem',
   'max-results' => 1000,
   'start-date' => $start_date,
   'end-date' => $end_date,
 );

Upvotes: 1

Nick Blexrud
Nick Blexrud

Reputation: 9603

Try removing the 0.

For example, I have a query like this:

ga:customVarName4=~Previous-Purchases;ga:customVarValue4==1

This gets my custom variable name that matches regex Previous-Purchases AND the custom variable value is equal to 1.

Upvotes: 0

Related Questions