Sub topic 3
Consent mode and ads personalization controls
This chapter assumes you know the GA4 Admin area, GA4 events and users, and consent rules such as GDPR. It covers consent mode, data sharing settings, data deletion requests, retention through the Admin API, and auditing a property against a written policy.
Consent mode and ads personalization controls
Consent mode passes the visitor's consent choices from your banner to Google tags. Set the defaults before the Google tag loads, then update them after the visitor decides.
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
// Run before the Google tag loads: deny until the user chooses.
gtag('consent', 'default', {
ad_storage: 'denied',
analytics_storage: 'denied',
ad_user_data: 'denied',
ad_personalization: 'denied'
});
// Run after the user accepts in your consent banner.
gtag('consent', 'update', {
analytics_storage: 'granted',
ad_storage: 'granted',
ad_user_data: 'granted',
ad_personalization: 'granted'
});ad_user_data controls whether data can be sent to Google for advertising. ad_personalization controls whether that data can be used for personalized ads.
Data sharing settings: Google products, modeling, support, and account specialists
Open Admin, then Property, then Data sharing settings. Review four switches:
| Setting | What it allows | Decision guide |
|---|---|---|
| Google products | Sharing with linked products such as Google Ads | Keep on only for linked products you use |
| Modeling | Google fills gaps with modeled data | Turn off if your policy forbids modeling |
| Technical support | Support staff can access your data | Enable only during a support case you approve |
| Account specialists | Google account reps can view your data | Enable only if your contract requires it |
Data deletion requests
Data deletion requests remove user-level data for the identifiers you specify. Use them for verified user requests, such as a person asking for their data to be erased. Treat each request as permanent, and record who approved it and why.
Reading and updating retention with the Admin API
The Admin API exposes retention settings at dataRetentionSettings. Read the current values with GET, then change them with PATCH and an updateMask.
# Read current retention settings
curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \
"https://analyticsadmin.googleapis.com/v1beta/properties/123456789/dataRetentionSettings"
# Set retention to 14 months and keep reset on new activity
curl -s -X PATCH \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"eventDataRetention":"FOURTEEN_MONTHS","resetUserDataOnNewActivity":true}' \
"https://analyticsadmin.googleapis.com/v1beta/properties/123456789/dataRetentionSettings?updateMask=eventDataRetention,resetUserDataOnNewActivity"Auditing a property against a privacy policy
Compare each setting with your written policy. The flow below shows the order of checks.
- Confirm consent defaults are
deniedin the tag. - Confirm each sharing switch matches the policy.
- Confirm the retention period matches the policy.
- Record the audit date and the reviewer.
Exercise
A policy requires event data kept for two months, but the property is set to FOURTEEN_MONTHS. Which API call fixes this, and what must the request body contain?
Show answer
Send a PATCH to dataRetentionSettings with updateMask=eventDataRetention and a body of {"eventDataRetention":"TWO_MONTHS"}.