Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Analytics retrieve custom variables statistics

Edit refurbished the question that was not clear

New to GA, I'm looking at the way to retrieve automatically custom variables data statistics

The query would have

  • a start and an end dates (possibly equal)
  • a variable name

For instance, a Page-level variable Brand takes only three possible values, that are set by the web server, and seen by the client.
The values are Apple, Google and Microsoft.

The query to Google-Analytics could be something like (pseudo-code), provided that I use an authentication token previously acquired

  ...getstatistics?myToken=123&variable=Brand&datefrom=20110121&dateto=20110121

And the result could be some xml like data

  <variable>Brand</variable><value>Apple</value><count>3214</count> 
  <variable>Brand</variable><value>Google</value><count>4321</count> 
  <variable>Brand</variable><value>Microsoft</value><count>1345</count> 

Meaning for instance that the page-level custom variable Brand was set to the value Apple by the web server (and thus seen by the client / sent to GA) 3214 times.

What is the correct way/protocol to query values/statistics from GA, in order to get statistics related to custom variables?

like image 567
Déjà vu Avatar asked Dec 22 '22 18:12

Déjà vu


1 Answers

So, this is my understanding of what you're doing:

You're setting page-level custom variables (important technical note: these need to be called before the _trackPageview or some other call, else they won't be tracked.)

Your code might looks something like this:

_gaq.push(['_setCustomVar', 2, 'Brand', 3]);

Now, when querying the Google Analytics API, its important to note that the slot # is very important, since the slot you're accessing is explicitly named in the query.

So, to do this, you'd need to set your dimensions to ga:customVarName2 and ga:customVarValue2, and decide what metric you're interesting it getting. You mention Page views, so you'd use ga:pageviews. (You're by no means limited to pageviews. You can use any Metric besides a couple of the AdWords specific ones.)

This query would return you all of the custom variable from this slot, and the number of pageviews associated with them.

You also mentioned you'd want to be able to filter by value.

You'd do that by setting the filter value to something like ga:customVarValue2==Apple.

You can see what a query like that would look like here in the query explorer.

Here's a sample screenshot: enter image description here

Finally, all Google Analytics API queries by default require you to set a date range, so you could query that on your own.

All you need to do is decide which library you want to use as interface, and you're set to go.

like image 103
Yahel Avatar answered Feb 07 '23 17:02

Yahel