68publishers / cookie-consent

:cookie: Cookie-consent widget with GTM, GCM & CMP integration
MIT License
113 stars 28 forks source link

Cannot read properties of undefined (reading 'consent_modal') #56

Closed thorewi closed 1 year ago

thorewi commented 1 year ago

Hi,

when I try to use this plugin on www.nutriadapt.cz, I get this error:

Uncaught TypeError: Cannot read properties of undefined (reading 'consent_modal')
    at re (cookie-consent.min.js:2:67959)
    at cookie-consent.min.js:2:75658
    at R.run (cookie-consent.min.js:2:75704)
    at n (cookie-consent.min.js:2:24382)
    at e.value (cookie-consent.min.js:2:24587)
    at e.value (cookie-consent.min.js:2:25828)
    at 6010 (cookie-consent.min.js:2:100)
    at o (cookie-consent.min.js:2:134498)
    at cookie-consent.min.js:2:134863
    at cookie-consent.min.js:2:134895

settings:

{
    "include_default_stylesheets": true,
    "autorun": true,
    "page_scripts": false,
    "security_storage_enabled_by_default": false,
    "cookie_name": "cc-settings",
    "personalization_storage_enabled_by_default": false,
    "analytics_storage_display_in_widget": true,
    "analytics_storage_event_trigger": "68publishers_analytics_storage",
    "personalization_storage_display_in_widget": false,
    "translations": [
        {
            "locale": "cs",
            "key": "consent_modal_title",
            "value": "Používáme cookies!"
        },
        {
            "locale": "sk",
            "key": "consent_modal_title",
            "value": "Používame súbory cookies!"
        },
        {
            "locale": "en",
            "key": "consent_modal_title",
            "value": "We use cookies!"
        },
        {
            "locale": "cs",
            "key": "consent_modal_primary_btn",
            "value": "Souhlasím"
        },
        {
            "locale": "en",
            "key": "consent_modal_primary_btn",
            "value": "I agree"
        },
        {
            "locale": "sk",
            "key": "consent_modal_primary_btn",
            "value": "Súhlasím"
        },
        {
            "locale": "cs",
            "key": "settings_modal_title",
            "value": "Nastavení cookies"
        },
        {
            "locale": "sk",
            "key": "settings_modal_title",
            "value": "Nastavenia cookies"
        },
        {
            "locale": "en",
            "key": "settings_modal_title",
            "value": "Cookie settings"
        },
        {
            "locale": "cs",
            "key": "settings_modal_before_consent_title",
            "value": "Použití cookies"
        },
        {
            "locale": "sk",
            "key": "settings_modal_before_consent_title",
            "value": "Používanie súborov cookies"
        },
        {
            "locale": "en",
            "key": "settings_modal_before_consent_title",
            "value": "Cookie usage"
        },
        {
            "locale": "sk",
            "key": "consent_modal_secondary_btn_settings",
            "value": "Prispôsobiť"
        }
    ],
    "functionality_storage_event_trigger": "68publishers_functionality_storage",
    "external_stylesheets": [],
    "settings_modal_transition": "zoom",
    "consent_modal_buttons_order": "primary_secondary",
    "ad_storage_event_trigger": "68publishers_ad_storage",
    "consent_modal_layout": "bar",
    "consent_modal_primary_button_role": "accept_all",
    "settings_modal_position": "left",
    "consent_modal_transition": "zoom",
    "functionality_storage_enabled_by_default": true,
    "cookie_expiration": "182",
    "ad_storage_display_in_widget": true,
    "analytics_storage_readonly": false,
    "locale_detection_strategy": "document",
    "analytics_storage_enabled_by_default": false,
    "consent_modal_position": "bottom center",
    "settings_modal_layout": "box",
    "revision": "0",
    "locales": [
        "cs",
        "sk",
        "en"
    ],
    "package_version": "0.4.5",
    "delay": "500",
    "functionality_storage_display_in_widget": true,
    "security_storage_display_in_widget": false,
    "security_storage_event_trigger": "68publishers_security_storage",
    "ad_storage_readonly": false,
    "consent_modal_secondary_button_role": "settings",
    "ad_storage_enabled_by_default": false,
    "force_consent": false,
    "hide_from_bots": true,
    "functionality_storage_readonly": true,
    "personalization_storage_event_trigger": "68publishers_personalization_storage",
    "gtmTagId": 64,
    "gtmEventId": -1
}

In html tag in lang attribute is cs.

Any advice what can be wrong? Thank you.

tg666 commented 1 year ago

Hi,

According to the stack of your error, it fails in orestbida/cookieconsent on this line.

It looks like the language code from <html lang="..."> is not among the translations, which is strange.

If the dictionary for the given translation does not exist, then the dictionary for en is used. If the dictionary en does not exist, the first one defined is used. If there is no dictionary then it ends up with the error you sent.

So it looks like the CookieConsentWrapper doesn't have any translations set even though they are provided to it, according to your settings.

Can you check in the console on the website if there are any dictionaries?

Snímek obrazovky 2023-05-24 v 19 13 42
thorewi commented 1 year ago

totally empty :(

Screenshot 2023-05-25 at 19 24 05
tg666 commented 1 year ago

Do you have the latest template imported into GTM that is compatible with the version 0.4.5? isn't there an older version?

thorewi commented 1 year ago

Great, it helped. I thought I imported it but maybe I forgot to press Save. Sorry for bothering you.

Ciantic commented 8 months ago

I'm getting this same error. I haven't yet installed GTM, I'm just adding this:

<html lang="fi">
<script src="https://cdn.jsdelivr.net/npm/68publishers-cookie-consent@0.4.8/dist/cookie-consent.min.js"></script>

No other JS code, just the script tag.

Error raised:

Uncaught TypeError: Cannot read properties of undefined (reading 'consent_modal')

tg666 commented 8 months ago

@Ciantic Hi, just adding the script won't work, you need to set up the bar. The GTM tag will ensure the correct settings and also add the script automatically to the page (no need to define it manually on the page). Theoretically it is possible to use the bar without GTM, but I recommend rather to use GTM.