How to filter by user parameter in the Google Analytics API?

I am trying to get a list of the most visited pages for a website from the Google Analytics API. I currently have the following code and it returns a list with a title, URL and the number of visitors to each page:

data_query = service.data().ga().get(**{
    'ids': 'ga:123456789',
    'dimensions': 'ga:pageTitle,ga:pagePath',
    'metrics': 'ga:pageviews',
    'start_date': '2013-12-31',
    'end_date': '2014-04-29',
    'sort': '-ga:pageviews',
})
feed = data_query.execute()

The problem is that all pages of the website can be displayed in Spanish or English, so as a result I get duplicate lines for the same URL, for example:

[
    ['/index/', 'Inicio', 23],
    ['/index/', 'Home', 57],
]

To be able to filter the results by language, I would get something like this:

[
    ['/index/', 'Inicio', 23, 'es'],
    ['/index/', 'Home', 57, 'en'],
]

Google Analytics, 'lang' ('dimension1'), html- en es:

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'xxx', 'yyy');
ga('send', 'pageview');
ga('set', 'dimension1', 'en');   // <----- or 'es'

</script>

data_query = service.data().ga().get(**{
    'ids': 'ga:123456789',
    'dimensions': 'ga:pageTitle,ga:pagePath,ga:dimension1',
    'metrics': 'ga:pageviews',
    'start_date': '2013-12-31',
    'end_date': '2014-04-29',
    'sort': '-ga:pageviews',
})

aways .


Update:

, , ga , :

ga('send', 'dimension1', 'en');
+4
2

, :

ga('set', 'dimension1', 'en');   // <----- or 'es'

?

, , .

Btw, , , , , page.

Google Analytics.

0

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


All Articles