Saurabh Vijayvargiya
Saurabh Vijayvargiya

Reputation: 176

How to get list of custom dimensions in google analytics api v4

I am looking for a method to get the list of custom dimensions in my analytics reports using API v4. In API v3 it was done using management API v3, but I could not found management API v4. Please suggest some solution.

Thanks Saurabh

Upvotes: 0

Views: 2426

Answers (1)

Matt
Matt

Reputation: 5168

Short Answer: Use the Analytics Management API V3 to list custom dimensions.

The Analytics Reporting API V4 is a stand alone API for querying your analytics data. It is listed in the Developer console as Analytics Reporting API V4.

Analytics Management API in console as Analytics API.

Python Example

analytics = build('analytics', 'v3', http=http)

dimensions = analytics.management().customDimensions().list(
  accountId='123456',
  webPropertyId='UA-123456-1',
).execute()

DISCOVERY_URI = ('https://analyticsreporting.googleapis.com/$discovery/rest')
analytics = build('analyticsreporting', 'v4', http=http, discoveryServiceUrl=DISCOVERY_URI)

analytics.reports().batchGet(
  body={
    'reportRequests': [
    {
      'viewId': '1234',
      'dateRanges': [{'startDate': '7daysAgo', 'endDate': 'today'}],
      'metrics': [{'expression': 'ga:sessions'}],
      'dimensions': [{'name': 'ga:dimension1}] # From the mgmt API V3.
    }]
  }

History

In V3 all of Analytics API's (Management, Metadata, Core Reporting, MCF Reporting, Realtime Reporting) were under one top level Service called analytics. But with the advent of the Analytics Reporting API V4 it was necessary to have a separate/stand-alone API so that you can use both the V3 Management API and the V4 Reporting API in the same application.

Upvotes: 0

Related Questions