@omatech/oma-cookies
v1.3.1
Published
Cookies consent manager
Downloads
4
Readme
Install the package
npm i @omatech/oma-cookies
Import the main js file into your project:
require('@omatech/oma-cookies/dist/js/omacookies.min');
Optionally you can copy into a public folder the JS file located inside
the /node_modules/@omatech/oma-cookies/dist/js
folder and link it in your HTML layout
<script src="/path_to_copied_file/omacookies.min.js"></script>
There are 2 approaches depending on your styling method:
A) If you are ONLY overriding CSS classes => Import the compiled CSS file
@import "~@omatech/oma-cookies/dist/css/omacookies.min.css"
Optionally you can copy into a public folder the CSS file located inside
the /node_modules/@omatech/oma-cookies/dist/css
folder and link it in your HTML layout
<link href="/path_to_copied_file/omacookies.min.css" rel="stylesheet">
B) If you want to override the variables and CSS classes => Import all the separated files
@import "~@omatech/oma-cookies/dist/scss/base"
@import "~@omatech/oma-cookies/dist/scss/variables"
//Your own SCSS file overriding the variables from the file above
@import "variables"
@import "~@omatech/oma-cookies/dist/scss/styles"
<meta name="viewport" content="width=device-width, initial-scale=1">
To start things up, you must add this somewhere in your HTML layout (preferably at the end)
<body>
...
<div id="omacookies"></div>
</body>
Every iframe must have the attribute data-omacookies-consent
which has 2 possible values marketing
or statistics
. This specitfy when the content will be un/blocked
The attribute data-omacookies-yt-video-id
is the ID found at the end of every YouTube video URL. In /watch?v=uu5k19UaCT0
the ID would be uu5k19UaCT0
<div
class="omac-iframe-youtube"
data-omacookies-consent="marketing"
data-omacookies-yt-video-id="uu5k19UaCT0"
></div>
The attribute data-omacookies-src
would work as the normal iframe src
attribute
You can add any attribute to the rendered iframe using the attribute data-omacookies-xxx
. Simply change xxx
for any other attribute. See the attribute width
shown in the example.
<div
class="omac-iframe"
data-omacookies-consent="statistics"
data-omacookies-src="https://example.com/"
data-omacookies-width="720"
></div>
It is required to add the type="text/plain"
attribute.
- For file JavaScript scripts
<script
class="omac-script"
type="text/plain"
data-omacookies-consent="statistics"
src="https://example.com/"
></script>
- For inline JavaScript code
<script
class="omac-script"
type="text/plain"
data-omacookies-consent="statistics"
>
console.log("Hello World!");
</script>
window.OMAC.SelectionModal.open();
Somewhere after the import of the omacookies
JS file we will override attributes from the main object.
We can set a new value for any language string with the following declaration:
window.OMAC.available_languages.es.select_box_title = 'Personalizar Cookies';
We can add as many languages as we want, we just need to follow the same object structure we already have for ES and EN.
You can copy the structure from /node_modules/@omatech/oma-cookies/src/lang/en.json
For example, we will add German language:
window.OMAC.available_languages.de = {
"constent_box_title": "Diese Website verwendet Cookies",
...
};
Make sure to set the language after you make any modifications to the available_languages
object.
window.OMAC.setLang("en");
Here we will add the website link where the user will be redirected to read the cookie policy.
window.OMAC.readMoreLink = "https://omatech.com/cookies.html";
Here we can set the appearance of the initial cookie dialog. The allowed values are modal
(default) or banner
.
window.OMAC.format = "banner";
The quick link is enabled by default. Disable it setting the following:
window.OMAC.enableQuickLink = false;
To open the cookies selection modal when disabled, use the this method
Here we can configure in which corner of the screen will the quick link be located, using the values top-right
, top-left
, bottom-right
or bottom-left
. The quick link will appear on the bottom-right
by default.
window.OMAC.quickLinkPosition = "bottom-left";
This project has MIT license. For further information, read the LICENSE
file.