Download the PHP package jfeltkamp/cookiesjsr without Composer

On this page you can find all versions of the php package jfeltkamp/cookiesjsr. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package cookiesjsr

Cookies JSR

Easy plug-able cookie consent management tool built with React.

This tool does not contain any services that implements external resources, such as Analytics or Youtube. It is an easily configurable framework, with which it is possible to obtain the user's consent to the use of cookies, to save his decisions (also in a cookie) and provides an event as entry point for dispatching own services.

Install

  1. Create your file where you define your groups and services.
  2. Create your file where you initialize the services.
  3. Place the following HTML before the closing body-tag.

... and you are done.

Example

(Documentation)

Example

This file basically gives the base config to the JS library (see object: ), where the library can find their config file. (Documentation)

But you can also dispatch your consent dependent services inside of this file. (Further best practices)

`

Documentation

In the config file are two objects expected: , and optinal .

The config object

In you define some options about the

  1. : Some common option about
    • where to find the translation,
    • how to display the cookie consent widget.
    • ... and more
  2. : The users decisions what cookies will be allowed or not, are saved in another 'required' cookie. Here you define the properties for this single cookie.
  3. : Each time the user saves changes of his cookie settings, a callback can be invoked, sending these data to the backend.
Parent Children Type
config object
cookie object (keys: name, expires, sameSite, secure)
callback object (keys: method, url, headers)
interface object (keys: openSettingsHash, ...)
services object (see docs here)
translation object, optional (see docs here)
Details
Parent Children Type: Description
cookie
name string: the cookie name
expires integer: (optional) time (ms) cookie is valid.
domain string: (optional) domain cookie is valid for.
path string: (optional) path cookie is valid for.
secure boolean: (optional, default: false)
sameSite string: (optional, None/Lax/Strict, default: Lax)
callback
url string: (optional) the callback url
method string: (optional, get/post, default: get)
headers object: (optional), key-value pairs
interface
openSettingsHash string: (optional, default: cookiesjsr) The location.hash value to open the cookie settings dialog.
showDenyAll boolean (optional, default: true) Add "deny all" button to dialog that makes all cookies forbidden.
translationQuery string (optional, path/url) the absolute path or url where translation data can be load. ("%lang_id" is placeholder for language ID ISO 639-1 e.g. "en". This option you can use, when you use static translation files. You can also add the translation to your config-file.
availableLangs array(string(2)): language IDs ISO 639-1 e.g. ["en", "de"]
defaultLang string(2): (optional, default: en) Fallback language, if requested language not available
groupConsent boolean: (optional, default: false) The user can only en-/disable entire groups not individual services. Services are not shown in detail.
cookieDocs boolean: (optional, default: false) Display links to cookie documentation where explicitly is described what 3rd-party services and cookies are used. This is required, if you use groupConsent. Link and link text are provided by translation.

The services object

The object is a simple homogeneous structure of multiple service groups containing the services that users have to accept or deny.

Each contained service in a group has 5 properties:

Property Type Description
key string (uid) The unique Id of the service. e.g. "gtag"
type string Group the service belongs to.
name string Display name shown in the dialog widget
uri string URL for the ext. documentation of the resource.
needConsent string If service needs users consent or not (required cookies)

The object

The content of this object is just the same as the content of a translation file.

If the translation from a CMS or similar the translation can also be included in the config file. In this case, the path to the config file must contain a placeholder for the language ID (% lang_id).

However, you have to decide how you want to load the translation. A good option is to load static files as they are offered here in the Git repo. In this case, simply adjust the path where the files are stored at .

If the translations are to be maintained via a CMS or similar, it can be advantageous to deliver the translation with the configuration, because otherwise two API calls will be executed in succession, which can delay the display of the app. To achieve that the config delivers the correct translation you will have to provide a translation parameter in the configQuery route (see paragraph below).

However, IF a translation object is included in the config, the translationQuery will not be invoked.

How the language is determined?

``

By the way: The app determines the language based on the lang parameter in the HTML tag. If no parameter is available, the default language of the browser is determining.

Base Config

Content of your : ` The base config tells the library where to find the config. If the config is load from an other domain, you must give an apiUrl (leave empty if not).

: (optional, e.g. 'https://hi-api.io/path') The base URL where your API can be reached. Leave empty if your website has same origin. No pending slash.

: (required) Path to your config-file (cookiesjsr-config.json). If your config-file contains the translation data, the path must include a param "%lang_id" for the language id. `

Processing consent, activation of 3rd-party services

In the code example above you see how to catch the event and distribute the users consents to the individual service activation. Here we want to have a look on how to handle the 3rd-party service activation. The content of the functions provided in the dispatcher event (activate and fallback).

In order to effectively suppress 3rd party cookies, the resources must already be switched off in the supplied source code. I.e. that corresponding script tags or iframes (these are the most common use cases) have to be manipulated so that they do not work. => We have to find a reversible knock-out technique.

What the function has to do is to reanimate the service.

What the function has to do is to repair gaps in the layout, inform user, that something is missing, or ask again if he now wants to activate the service.

Reversible knock-outs for and

``

Re-animation of knocked out services

`

En-/disable 3rd-party services from anywhere

It is possible to activate third party services from anywhere on the website. It is not necessary to open the cookie widget for this. It just has to be fired a Javascript event .

Suppose you have a link on the page that should be used to activate the Matomo service...

` ... your javascript could look like this.

` As you can see, the event expects a data object, which is stored in the detail property of the CustomEvents. This data object should have at least one of the following properties:

Property Value Description
all boolean En-/disables all 3rd-party services
services object An object with key/value-pairs where the is the id of a 3rd-parts service and is a boolean if the service should be enabled (true) or disabled (false).
groups object An object with key/value-pairs where the is the id of a entire group of services and is a boolean if the services should be enabled (true) or disabled (false).

Callback

If you have defined a callback URL, this will be called (to your backend or wherever you want) immediately after the cookiesjsr cookie was set or updated. When you send a POST request, the answer of the callback should be a JSON response. The returned data is available in a JS event. The following code is required to process the returned data.

`

Styling

If you just want to customize colors use css vars. Copy the following code to your css and play with the values.

You shouldn't have any trouble overwriting the css. The CSS is plain BEM-style and there are no "!importants" or inline-styles.

Rewrite CSS

The original .scss files are in the repo. If you want to do a full CSS rewrite, this might be a good starting point. In that case, you can simply do without integrating the original CSS.

The MarkUp is fixed because the JS is a rendered React-App. You can't change anything here.


All versions of cookiesjsr with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package jfeltkamp/cookiesjsr contains the following files

Loading the files please wait ....