Jan Pöschko
Jan Pöschko

Reputation: 5570

Define Google Analytics 4 custom dimensions via API

Is there a way to programmatically define custom dimensions using the Google Analytics Admin API (that works with GA4)?

I'm talking about defining the dimensions ahead of time so I can send them along with events, which is what you'd manually do in the Google Analytics user interface (under All events > Manage Custom Definitions). This is what I'd like to do programmatically. Once they're defined, sending these custom dimensions along with tracking events is easy enough (using gtag).

Apparently, this was possible in the previous version of the API, but that API says that it "does not support GA4 properties".

Upvotes: 3

Views: 1806

Answers (2)

Juan Almeida
Juan Almeida

Reputation: 33

You already can programmatically define/create custom dimensions and metrics with the Google Analytics Admin API for GA4 properties.

Custom dimensions

Can be created with this method providing:

  • description
  • displayName
  • parameterName (it hasn't need to exist beforehand)
  • scope (User or Event)

Custom metrics

Can be created with this method providing:

  • description
  • displayName
  • measurementUnit
  • restrictedMetricType
  • scope (Metric_Scope_unspecified or Event)

Warning from Google: This is an early preview version of the API and is subject to change. While we will try to notify you of upcoming changes, you should expect to encounter breaking changes before the APIs are publicly released.

Upvotes: 3

Ilya Kuleshov
Ilya Kuleshov

Reputation: 584

Jan,

You are correct that the Google Analytics Management API V3 cannot be used to configure GA4 properties. The Analytics Admin API V1, which supports GA4, does not currently have methods to create custom metrics/dimensions.

I will update this question once we have more information on when this feature can become available.

Thanks, Ilya

The Google Analytics Team

Upvotes: 1

Related Questions