def rename_existing_ga4_custom_events()

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


def rename_existing_ga4_custom_events(configuration: map, old_prefix, new_prefix):
  """
  Renames existing custom events in Google Analytics 4 by replacing the old prefix with the new prefix.

  Args:
    configuration: A dictionary containing the Google Analytics 4 property ID and data stream ID.
    old_prefix: The old prefix to be replaced.
    new_prefix: The new prefix to be used.

  Raises:
    GoogleAnalyticsAdminError: If an error occurs while renaming the custom events.
  """
  existing_event_rules = load_existing_ga4_custom_event_objs(configuration)
  for page in existing_event_rules.pages:
    for create_event_rule in page.event_create_rules:
      if create_event_rule.destination_event.startswith(old_prefix):
        update_custom_event_with_new_prefix(create_event_rule, old_prefix, new_prefix)