Why Heavy CMPs Destroy Your Core Web Vitals
Many privacy compliance tools require inserting external scripts at the very top of your <head> section. These scripts block the HTML parser, force massive DNS lookups, and execute long tasks that cause severe Interaction to Next Paint (INP) delays before users can even click your navigation links.
Setting Up Google Consent Mode v2
To maintain advertising compliance in the European Economic Area (EEA), you must define default consent states before Google tags execute, and update them when the user interacts with your banner:
function updateConsent(analyticsGranted, marketingGranted) {
gtag('consent', 'update', {
'analytics_storage': analyticsGranted ? 'granted' : 'denied',
'ad_storage': marketingGranted ? 'granted' : 'denied',
'ad_user_data': marketingGranted ? 'granted' : 'denied',
'ad_personalization': marketingGranted ? 'granted' : 'denied'
});
}
Persisting User Choice in LocalStorage
Once a visitor selects their preferences, save the timestamped JSON state into localStorage.setItem('cookie_consent', ...). Subsequent page loads will read this record immediately without flashing the banner again.