omatech/oma-cookies

Cookie consent manager

Installs: 5

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 6

Forks: 0

Open Issues: 0

Language:JavaScript

v1.3.1 2022-03-28 11:14 UTC

This package is auto-updated.

Last update: 2024-10-28 16:59:56 UTC


README


Omatech Logo

Oma-cookies

Built-in solution that allows the control of cookies,
enabling GDPR compliance for Omatech internal projects.

Table of contents

Installation

Install the package

npm i @omatech/oma-cookies

JavaScript import

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>

CSS/SASS import

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"

Regardless of what option you choose, make sure this line is in your HTML layout so the responsive works properly.

<meta name="viewport" content="width=device-width, initial-scale=1">

Implementation

To start things up, you must add this somewhere in your HTML layout (preferably at the end)

<body>
...
<div id="omacookies"></div>
</body>

Iframes

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

YouTube videos

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>

Generic iframe

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>

Scripts

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>

↑ Back to top

Methods

Open cookies consent selection modal

window.OMAC.SelectionModal.open();

↑ Back to top

Configuration

Somewhere after the import of the omacookies JS file we will override attributes from the main object.

Override language strings

We can set a new value for any language string with the following declaration:

window.OMAC.available_languages.es.select_box_title = 'Personalizar Cookies';

Adding a new language

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",
    ...
};

Setting the default language

Make sure to set the language after you make any modifications to the available_languages object.

window.OMAC.setLang("en");

Read more link

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";

Format

Here we can set the appearance of the initial cookie dialog. The allowed values are modal (default) or banner.

window.OMAC.format = "banner";

Enable/disable quick link

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

Quick link position

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";

↑ Back to top

License

This project has MIT license. For further information, read the LICENSE file.

↑ Back to top

Contact

↑ Back to top