Learn business growth with Google Analytics 4 › Forums › Google Analytics 4 › Implementing data retention settings in ga4 using python › Reply To: Implementing data retention settings in ga4 using python
-
Hey there! So with GA4, the data you’ve been accessing so far, like dimensions and metrics, typically comes from the Data API. That’s great for getting report-like data.
However, if you’re trying to access settings from a GA4 property or account, you need to switch gears a bit and use the Admin API instead.
Good news though: there’s a trove of Python samples for the GA4 admin API available you can check out and start from [here](https://github.com/googleapis/python-analytics-admin/tree/main/samples).
And guess what? Here’s another [sample code](https://github.com/googleapis/python-analytics-admin/blob/380b4264003b17b802b7099b98837694cd0b87d1/samples/generated_samples/analyticsadmin_v1alpha_generated_analytics_admin_service_get_data_retention_settings_sync.py) I’ve found that might be just what you’re looking for. It’s supposed to retrieve data retention settings, which sounds like what you’re after.
Just a heads-up though, when you’re using the Admin API, take extra care! You could unintentionally change settings or even delete properties – definitely want to avoid that. Happy coding!