Automad automatically displays a cookie consent banner when a page includes content from an embed block, such as YouTube videos, SoundCloud tracks or social media posts. The embedded content is only loaded after the visitor has accepted the use of third-party cookies. This helps you comply with the GDPR.
The consent check is enabled by default. It can be turned off by setting AM_CONSENT_CHECK_ENABLED to false in config/config.php. In that case, no banner is displayed, embedded content is loaded right away and the am-consent wrapper described below is no longer processed.
Custom Script Wrapper
For third-party scripts and iframes that aren't automatically handled, such as code added in the custom HTML fields, you can use the am-consent wrapper component to request visitor consent before loading them.
The am-consent component can handle both linked .js files and inline JavaScript code, as well as iframes.
Inline JavaScript can be added to a custom HTML field as follows:
<am-consent type="script">
console.log('Hello you!');
</am-consent>
To fetch and run an externally linked script file, you can use the src attribute:
<am-consent type="script" src="https://domain.com/script.js"></am-consent>
Without a type attribute, or with type="iframe", the component is replaced by an iframe once the visitor has given consent. All other attributes, such as src, width or height, are passed on to the created <script> or <iframe> element:
<am-consent type="iframe" src="https://domain.com/widget" width="600" height="400"></am-consent>
Styling the Cookie Banner
Automad lets you customize the texts and colors of the consent banner and of the placeholders that are displayed instead of embedded content. The labels of all related fields start with Cookie consent:. The following settings are available:
- Texts — the banner text, the labels of the accept, decline and revoke buttons, the tooltip text and the placeholder text
- Banner colors — text color, background and border color
- Button colors — text color, background and border color, each for the primary and the secondary button
- Placeholder colors — text color and background
This way, the banner and placeholders feel like part of your design, not a foreign element. All cookie consent customization settings can be found either in Global Data and Files → Customizations or under the Customizations tab in the page settings.