Cookies are small text files that are added to the visitors web browser by the website they visit. Cookie consent banners are required to inform the users of the usage of the cookies in order for the website to be transparent about the data collection practices.
This post will guide you how you can add cookie consent banner less than 5 mins using Cookieconsent library by osano
It is advisable to include these scripts in common html header or footer that will be included in every page of your website.
First you need to add popup style sheet to your website. copy following and include it in your web page before end of head tag or end of body tag
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/cookieconsent@3/build/cookieconsent.min.css" />
Then after the styles you can copy and paste following javascript code
<script src="https://cdn.jsdelivr.net/npm/cookieconsent@3/build/cookieconsent.min.js" data-cfasync="false"></script>
<script>
window.cookieconsent.initialise({
"palette": {
"popup": {
"background": "#3c404d",
"text": "#d6d6d6"
},
"button": {
"background": "#8bed4f"
}
},
"theme": "classic",
"type": "opt-in",
"content": {
"message": "This website uses cookies to ensure you get the best experience on our website.",
"dismiss": "Got it",
"allow": "Allow cookies",
"link": "privacy policy",
"href": "www.example.com/cookiepolicy"
}
});
</script>
As you can see in the code we did two things above. First we include the library and then we passed the configurations for popup. let’s go through each function
palette.popup.text | popup text color |
palette.popup.background | popup bg color |
palette.button.text | button text color |
paletter.button.background | button text color |
theme | null | edgeless | classic |
type | null | opt-in | opt-out |
content.message | popup message |
content.dismiss | dismiss button text |
content.allow | allow button text |
link | website policy link text |
href | website policy link |
Happy coding ! let others know alternative easy to implement plugins you know.