def create_custom_dimension()

in python/ga4_setup/setup.py [0:0]


def create_custom_dimension(configuration: map, field_name: str, display_name: str):
  """
  Creates a custom dimension in Google Analytics 4 based on the provided configuration.

  Args:
    configuration: A dictionary containing the Google Analytics 4 property ID.
    field_name: The name of the field to be used as the custom dimension.
    display_name: The display name of the custom dimension.

  Raises:
    GoogleAnalyticsAdminError: If an error occurs while creating the custom dimension.
  """
  client = admin_v1alpha.AnalyticsAdminServiceClient()

  custom_dimension = admin_v1alpha.CustomDimension()
  custom_dimension.parameter_name = field_name
  custom_dimension.display_name = display_name
  custom_dimension.scope = "USER"

  request = admin_v1alpha.CreateCustomDimensionRequest(
    parent=f"properties/{configuration['property_id']}",
    custom_dimension=custom_dimension,
  )

  client.create_custom_dimension(request=request)