Skip to content

Cookie consent

Petr Marek edited this page Dec 17, 2021 · 2 revisions

Setup

Add cookie consent assets to application.js

//= require folio/cookie_consent/cookie_consent

and application.sass

@import 'folio/cookie_consent/cookie_consent'

and set cookie consent config in an initializer. Common cookie types can be given as symbols, custom have to be passed as a hash. See known cookie types

Rails.application.config.folio_cookie_consent_configuration = {
  enabled: true,
  cookies: {
    necessary: [
      :cc_cookie,
      {
        name: "_my_custom_cookie",
        expiration: [2, :years],
        description: {
          cs: "Cesky popisek cookie",
          en: "English description",
        }
      },
      :s_for_log,
      :u_for_log,
      {
        name: "show_brand_new_.*",
        is_regex: true,
        expiration: :end_of_session,
        description: {
          cs: "Udržuje informaci o zobrazení vlaječky \"novinka\" u produktů.",
          en: "Maintains information about \"brand new\" label being displayed.",
        }
      },
    ],
    analytics: [
      :_ga,
      :_gid,
      {
        name: "_ahoy_visit",
        expiration: :end_of_session,
        description: {
          cs: "Udržuje identifikaci uživatele.",
          en: "Used to identify user.",
        }
      },
      {
        name: "_ahoy_visitor",
        expiration: :end_of_session,
        description: {
          cs: "Udržuje identifikaci uživatele.",
          en: "Used to identify user.",
        }
      },
    ],
    marketing: [
      :_gcl_au,
    ]
  }
}

Google Tag Manager

Once user accepts/rejects cookies a message containg the allowed cookie types is pushed to google tag manager if present.

Example messages:

{ "event": "cookieConsent", "level": ["necessary"] }
{ "event": "cookieConsent", "level": ["necessary", "analytics"] }
{ "event": "cookieConsent", "level": ["necessary", "analytics", "marketing"] }

Reopening the settings modal

Folio listens for click on .f-cookie-consent-link so feel free to add the class to a menu item / button anywhere in your code to open the cookie consent settings modal upon clicking.

Clone this wiki locally