1

How would I go about passing multiple dimensions when executing a Google Analytics Reporting API v4 Query. For example how would I pass ga:dimension7 in addition to ga:dimension5 in my dimensions?

function queryReports() {
        gapi.client.request({
            path: '/v4/reports:batchGet',
            root: 'https://analyticsreporting.googleapis.com/',
            method: 'POST',
            body: {
                reportRequests: [
                    {
                        viewId: VIEW_ID,
                        dateRanges: [
                            {
                                startDate: '7daysAgo',
                                endDate: 'today'
                            }
                        ],
                        dimensions: [
                            {
                                name: 'ga:dimension5'
                            }
                        ],
                        metrics: [
                            {
                                expression: 'ga:totalEvents',
                                alias: 'orderNumber'
                            }
                        ],
                        filtersExpression: 'ga:eventCategory==xxx,ga:eventAction==xxx',
                        filtersExpression: 'ga:dimension5=~\^\\\[.*\\\]\$'
                    }
                ]
            }
        }).then(displayResults, console.error.bind(console));
    }

When I separate them with comma,then I have the error below:

wrong message

Any idea?

3 Answers 3

3

I have the answer below:

POST https://analyticsreporting.googleapis.com/v4/reports:batchGet
{
  "reportRequests":[
  {
    ...
    "dimensions": [
    {
      "name":"ga:dimension3"
    },{
      "name":"ga:dimension5"
    }],
    ...
  }]
}

see details here guide to migrate the Core Reporting API V3 to the Analytics Reporting API V4

Sign up to request clarification or add additional context in comments.

Comments

2
sample_request = {
      'viewId': 'xxxxxxxxx',
      'dateRanges': {
          'startDate': datetime.strftime(datetime.now() - timedelta(days = 30),'%Y-%m-%d'),
          'endDate': datetime.strftime(datetime.now(),'%Y-%m-%d')
      },

      "dimensions": 
      [
        {"name": "ga:date"},
        {"name": "ga:userType"},
        {"name": "ga:sessionDurationBucket"}
      ],
      "metrics": 
      [
        {"expression": "ga:sessions"},
        {"expression": "ga:newUsers"},
        {"expression": "ga:bounces"}
      ],
    }

Easy to understand pattern here for calling multiple dimensions and metrics. Replace 'ga:' with your choice of Dimensions and Metrics. Exclude date and time if ou want. It will show specific sessions occurring on that dates

Comments

0

Your can use multiples dimencions like this

dimensions: "ga:date,ga:campaign"

Here share an example:

function getData() {
  const response = await jwt.authorize();
  const result = await google.analytics("v3").data.ga.get({
    auth: jwt,
    ids: "ga:" + view_id,
    "start-date": "2021-05-01",
    "end-date": "today",
    dimensions: "ga:date,ga:campaign",
    metrics: "ga:users",
    sort: "ga:campaign,ga:date",
  });

  console.dir(result);
};

getData();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.