in python/ga4_setup/setup.py [0:0]
def rename_existing_ga4_custom_dimensions(configuration: map, old_prefix, new_prefix):
"""
Renames existing custom dimensions in Google Analytics 4 by replacing the old prefix with the new prefix.
Args:
configuration: A dictionary containing the Google Analytics 4 property 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 dimensions.
"""
page_result = load_existing_ga4_custom_dimension_objs(configuration)
for page in page_result.pages:
for custom_dimension in page.custom_dimensions:
if custom_dimension.display_name.startswith(old_prefix):
update_custom_dimension_with_new_prefix(custom_dimension, old_prefix, new_prefix)