shasho
shasho

Reputation: 161

how to use custom dimension in batchGet

When I try to do batchGet with custom dimension I get an error "Unknown dimension(s):"

This code works fine

analyticsreporting.reports.batchGet({
    requestBody: {
        reportRequests: [
            {
                viewId: 'XXXXXXXXX',
                dateRanges: [
                    {
                        startDate: '7daysAgo',
                        endDate: 'today',
                    },
                ],
                dimensions: [
                    {
                        name: 'ga:eventCategory'
                    }
                ],
                metrics: [
                    {
                        expression: 'ga:totalEvents',
                    },
                ],
            },
        ],
    },
}).then((res) => {
    console.log(res);
})

but when I use for dimension a custom analytics dimension , replacing ga:eventCategory with ga:store

dimensions: [
             {
             name: 'ga:store'
              }
           ],

I am getting Error: Unknown dimension(s): ga:store

The dimension "store" is working on analytics GUI

The dimension "store" is working on analytics GUI

Upvotes: 1

Views: 271

Answers (1)

vinoaj
vinoaj

Reputation: 1674

In the reporting API you need to refer to the dimension by its index rather than its name. This is because the name can change over time, but the index never does.

Assuming store is in index 2, then you would use this code:

dimensions: [
             {
             name: 'ga:dimension2'
              }
           ]

Upvotes: 1

Related Questions