Google Analytics retrieves custom variable statistics.

Edit edited an incomprehensible question

New to GA, I’m looking for a way to automatically get statistics of user data variables

The request would have

  • start and end date (possibly equal)
  • variable name

For example, a brand page-level variable takes only three possible values, which are set by the web server and viewed by the client.
Values ​​are Apple, Google, and Microsoft.

The request in Google Analytics may be something like (pseudo-code), provided that I used a previously purchased authentication token

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

And the result may be some xml as 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> 

The point, for example, is that the page-level custom variable at the page level was set to Apple by the web server (and thus visible to the client / sent to GA) 3214 times.

What is the correct way / protocol for requesting values ​​/ statistics from GA to get statistics related to user variables?

+4
source share
2 answers

So this is my understanding of what you are doing:

You are setting page-level custom variables (important technical note: they must be called before calling _trackPageview or another call, otherwise they will not be tracked.)

Your code might look something like this:

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

Now, when you request the Google Analytics API, it’s important to note that slot # is very important because access to the slot is explicitly specified in the request.

So, for this you will need to set your sizes in ga:customVarName2 and ga:customVarValue2 , and decide which metric you are interested in getting. You specify page types, so use ga:pageviews . (You are by no means limited to viewing pages. You can use any metric, except for a pair specific to AdWords.)

This query will return you the entire user variable from this slot and the number of pageviews associated with them.

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

You would do this by setting the filter value to something like ga:customVarValue2==Apple .

You can see what a type query looks like in the query explorer .

Here is an example screenshot: enter image description here

Finally, for all Analytics API requests, the default date range is set so that you can request it yourself.

All you have to do is decide which library you want to use as an interface, and you are ready to go.

+9
source

Google has a handy resource called Google Analytics Data Explorer that can help answer many of your questions, allowing you to experiment through the interface while you log in with your Google Analytics credentials.

When you add parameters using your tools, the system will automatically create your URL / request.

If that’s not enough, Google also has Interactive Examples using JavaScript . Like the data explorer, you can also log in with your Google Analytics credentials and run examples to see which data will be returned.

These tools are awesome because they help you understand how to set up the exact data you are looking for.

+2
source

Source: https://habr.com/ru/post/1336425/


All Articles