Omschrijving
This script is part of Google’s Global Site Tag (gtag.js) framework, specifically handling user consent settings for various types of data storage and processing. Here’s a breakdown of its functions:
- Data Layer Initialization:
window.dataLayer = window.dataLayer || []; This line ensures that the dataLayer variable exists. It’s a global array used by Google Tag Manager to store and manage data. If dataLayer already exists, it’s left unchanged; if not, it’s initialized as an empty array.
- gtag Function:
function gtag(){dataLayer.push(arguments);} Defines the gtag function, which is used to send data to Google Analytics and related services. It works by pushing the arguments it receives into the dataLayer.
- Consent Configuration:
gtag('consent', 'default', {...}); Sets default consent settings for various purposes. These settings dictate how different types of data can be used or stored based on user consent. The parameters specified include:ad_storage: Ad-related data storage (e.g., cookies for ad targeting). Here, it’s set to 'denied', meaning this type of storage won’t occur unless consent changes.analytics_storage: Data storage for analytics purposes. Set to 'granted', allowing analytics tools like Google Analytics to store data by default.ad_user_data: Personal data collected from advertisements. Also denied.ad_personalization: Use of personal data for ad personalization. Denied as well.
This script essentially configures how the website should handle user data based on their consent, aligning data usage with privacy preferences and legal requirements like GDPR. It is crucial for managing user data responsibly and respecting user privacy.
<script>
// Define dataLayer and the gtag function.
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('consent', 'default', {
'ad_storage': 'denied',
'ad_user_data': 'denied',
'ad_personalization': 'denied',
'analytics_storage': 'granted'
});
</script>