I'm working on automating the update of our internal IP addresses through API requests, using a centralized list of IPs. While I've successfully listed the data streams within our properties, I'm stuck at accessing the internal traffic settings to read and update them programmatically.
The documentation seems limited, or I might be missing the correct navigation path. I've gone through Data Streams to Web Stream Details and tried to find a way to Configure Tag Settings for defining internal IPs, but no luck so far. Any guidance on how to proceed with defining internal traffic rules via API would be greatly appreciated.
Navigational Path:
Data Streams -> Web stream details > Configure Tag Settings > Define IP addresses whose traffic should be marked as internal > define internal traffic > Edit internal traffic rule > rule name: 'my_interal_ip'.
Here is a snapshot of my code that has lead me the far:
from google.oauth2 import service_account
from google.analytics.admin import AnalyticsAdminServiceClient
# Service account key file content
SERVICE_ACCOUNT_INFO = {
"type": "service_account",
"project_id": "example-ga4-analytics",
"private_key_id": "987666543210",
"private_key": "-----BEGIN PRIVATE KEY-----\ABCD123==\n-----END PRIVATE KEY-----\n",
"client_email": "example@example-ga4-analytics.iam.gserviceaccount.com",
"client_id": "1234567890",
"universe_domain": "googleapis.com"
}
# Create credentials object
credentials = service_account.Credentials.from_service_account_info(SERVICE_ACCOUNT_INFO)
# Create a client
client = AnalyticsAdminServiceClient(credentials=credentials)
# Fetch the property with the provided ID
property_id = "1234567890"
# Verify the format of the 'name' parameter before making the API call
property_name = f"properties/{property_id}"
print(f"Property Name for API call: {property_name}") # This line is added to verify the 'name' parameter
# Make the API call
response = client.get_property(name=property_name)
# Print property details
print(f"Property Name: {response.display_name}")
print(f"Property ID: {response.name}")
Where to go from here to update these fields, or add more?