Using and querying custom dimensions in the Google Analytics API

I am trying to query my Analytics (Universal) to get a list of metrics sorted by user dimension.

In July, the Google Analytics API Blog announced:

"Developers can use custom parameters to send unique identifiers to Google Analytics, and then use the underlying reporting API to retrieve these identifiers along with other Google Analytics data.

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

Despite this, I could not get any results from my Google Analytics. My submit function is below:

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

Unfortunately, a GA query using the filter "ga: dimension1 == red" does not get 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 also tried using custom segments to retrieve data, but it didn't help:

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

Data is displayed in custom reports in GA. How can I access it through the API?

+6
source share
2 answers

You need to include the measurement in the query. For example, 'dimension': 'ga:dimension1' , then use your filter 'ga:dimension1==red' . The query explorer is very useful for testing API queries.

+9
source

Hey, this is very helpful. Thanks a lot for your answer. Let me also answer this question with an example: let it be for a certain size ga, the syntax will look like this: ga: landingPagePath == "whatever you want" now we say that there is a user parameter called pagepath, which is customdimension1. Therefore, the syntax will be ga: dimension1 == "what you need"

-1
source

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


All Articles