Exemplos completos
Esta página contém exemplos técnicos e tutoriais em vídeo para integrar e configurar a solução Cookie Consent.
Exemplo 1: Implementação básica num site
Exemplo do TermsFeed Cookie Consent num site básico com o script do Google Analytics adicionado.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Basic Cookie Consent Example</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is a basic example of TermsFeed Cookie Consent.</p>
<button id="changePreferences">Cookie Settings</button>
<!-- Cookie Consent -->
<script type="text/javascript" src="//www.termsfeed.com/public/cookie-consent/4.2.0/cookie-consent.js" charset="UTF-8"></script>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function () {
cookieconsent.run({
"notice_banner_type": "simple",
"consent_type": "express",
"palette": "light",
"language": "en",
"website_name": "My Website",
"website_privacy_policy_url": "https://example.com/privacy",
"open_preferences_center_selector": "#changePreferences",
"page_load_consent_levels": ["strictly-necessary"]
});
});
</script>
<noscript>Free cookie consent by <a href="https://www.termsfeed.com/">TermsFeed</a></noscript>
<!-- Google Analytics (tagged) -->
<script type="text/plain" data-cookie-consent="tracking">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>
Exemplo 2: Implementação com o Google Consent Mode V2
Exemplo do Consentimento de Cookies do TermsFeed com o Google Consent Mode V2 integrado.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>E-commerce Store</title>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){
dataLayer.push(arguments);
}
gtag('consent', 'default', {
'ad_storage': 'denied',
'ad_user_data': 'denied',
'ad_personalization': 'denied',
'analytics_storage': 'denied'
});
</script>
<script async src="https://www.googletagmanager.com/gtag/js?id=TAG_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'TAG_ID');
</script>
</head>
<body>
<h1>Our Shop</h1>
<button id="cookieSettings" style="position:fixed; bottom:20px; right:20px;">
Cookie Settings
</button>
<!-- Cookie Consent -->
<script src="//www.termsfeed.com/public/cookie-consent/4.2.0/cookie-consent.js" charset="UTF-8"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
cookieconsent.run({
"notice_banner_type": "headline",
"consent_type": "express",
"palette": "dark",
"language": "en",
"website_name": "Shop",
"website_privacy_policy_url": "https://shop.example.com/privacy",
"open_preferences_center_selector": "#cookieSettings",
"page_load_consent_levels": ["strictly-necessary"],
"notice_banner_reject_button_hide": false,
"callbacks": {
"scripts_specific_loaded": (level) => {
switch(level) {
case 'targeting':
gtag('consent', 'update', {
'ad_storage': 'granted',
'ad_user_data': 'granted',
'ad_personalization': 'granted',
'analytics_storage': 'granted'
});
break;
}
}
},
"callbacks_force": true
});
});
</script>
<noscript>Cookie consent by <a href="https://www.termsfeed.com/">TermsFeed</a></noscript>
</body>
</html>
Tutoriais em vídeo
Aprenda a integrar e a utilizar a ferramenta de consentimento de cookies através dos nossos tutoriais em vídeo:
- Como adicionar um banner gratuito de aviso de consentimento de cookies utilizando a nossa ferramenta gratuita de consentimento de cookies
- Como integrar o Google Consent Mode V2 com o nosso Consentimento de Cookies Gratuito
- Como bloquear scripts antes do consentimento do utilizador com o Consentimento de Cookies Gratuito
- Como adicionar um botão para permitir que os visitantes abram as Preferências de Cookies ao utilizar o banner de aviso gratuito de consentimento de cookies
Tutoriais adicionais
- Para obter mais orientações, veja mais tutoriais no nosso canal do YouTube e na lista de reprodução “Como fazer”.