Complete Examples
This page contains technical examples and video tutorials for integrating and configuring the Cookie Consent solution.
Example 1: Basic Website Implementation
Example of TermsFeed Cookie Consent on a basic website with Google Analytics script added.
<!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>
Example 2: Implementation with Google Consent Mode V2
Example of TermsFeed Cookie Consent with Google Consent Mode V2 integrated.
<!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>
Example 3. Implementation with Cookie Consent & Microsoft UET Consent.
add complete example implementation code here
Video Tutorials
Learn how to integrate and use the Cookie Consent tool through our video tutorials:
- How to add a Free Cookie Consent Notice banner using our Free Cookie Consent tool
- How to integrate Google Consent Mode V2 with our Free Cookie Consent
- How to block scripts before user consent with Free Cookie Consent
- How to add a button to allow visitors to open the Cookie Preferences when using the Free Cookie Consent notice banner
Additional Tutorials
- For further guidance, watch more tutorials on our YouTube channel and in the “How-To” playlist.