Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Cannot read property 'show' of undefined #153

Closed
blueamerican opened this issue Aug 7, 2020 · 14 comments
Closed

Uncaught TypeError: Cannot read property 'show' of undefined #153

blueamerican opened this issue Aug 7, 2020 · 14 comments

Comments

@blueamerican
Copy link

TYPO3 9.5.20
cookieman 2.5.1

When clicking the accept or deny button, i get the error above in the chrome console. See attached screen.

In Firefox i get the error:
Uncaught TypeError: t is undefined

Hint:
If i exchange the <div id="cookieman-modal"
data-cookieman-showonce="1"
data-cookieman-settings...

part with the code from your demos, it works.

@blueamerican
Copy link
Author

error

@jonaseberle
Copy link
Member

jonaseberle commented Aug 7, 2020

Hi Markus,

I reckon that you have not defined any tracking objects.

Does this happen in a default install after you have included the static TypoScript templates (including the examples)?

Maybe you want to post your Tracking Object TypoScript.

@blueamerican
Copy link
Author

plugin.tx_cookieman.settings.trackingObjects {
    Matomo {
        # inline scripts would break Content-Security-Policy: script-src
        # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src
        inject (
            <script data-what="Matomo" src="/fileadmin/js/cookieman-inject.js"></script>
        )

        show {
            _pk_id {
                duration = 13
                durationUnit = months
                type = cookie_http+html
                provider = Matomo
                #Pattern searches for all cookies that are named like _pk_id.{website ID}.{user hash}
                htmlCookieRemovalPattern = ^_pk_id\.\d+\.[a-fA-F0-9]+$
            }

            _pk_ref {
                duration = 6
                durationUnit = months
                type = cookie_http+html
                provider = Matomo
                htmlCookieRemovalPattern = ^_pk_ref\.\d+\.[a-fA-F0-9]+$
            }

            _pk_ses {
                duration = 30
                durationUnit = minutes
                type = cookie_http+html
                provider = Matomo
                htmlCookieRemovalPattern = ^_pk_ses\.\d+\.[a-fA-F0-9]+$
            }

            _pk_cvar {
                duration = 30
                durationUnit = minutes
                type = cookie_http+html
                provider = Matomo
                htmlCookieRemovalPattern = ^_pk_cvar\.\d+\.[a-fA-F0-9]+$
            }

            _pk_hsr {
                duration = 30
                durationUnit = minutes
                type = cookie_http+html
                provider = Matomo
                htmlCookieRemovalPattern = ^_pk_hsr\.\d+\.[a-fA-F0-9]+$
            }
        }
    }
}


plugin.tx_cookieman {
    # see documentation: https://github.com/dmind-gmbh/extension-cookieman
    settings {
        groups {
            # extend group (already configured in the base template)
            mandatory {
                trackingObjects {
                    10 = fe_typo_user
                }
            }

            # a new group
            marketing {
                trackingObjects {
                    0 = Matomo
                    #10 = GoogleAnalytics
                    #20 = GoogleTagManager
                    #30 = Bing
                    #40 = FacebookPixel
                }

                respectDnt = 1
                showDntMessage = 1
            }
        }
    }
}

@blueamerican
Copy link
Author

my cookieman-inject.js:

console.log('cookieman: I would inject ' + document.currentScript.dataset.what + ' now...')
var _paq = _paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function () {
    var u = "//stats.mydomain.de/";
    _paq.push(['setTrackerUrl', u + 'piwik.php']);
    _paq.push(['setSiteId', '2']);
    var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
    g.type = 'text/javascript';
    g.async = true;
    g.defer = true;
    g.src = u + 'piwik.js';
    s.parentNode.insertBefore(g, s);
})();

@jonaseberle
Copy link
Member

Can you confirm with the Template Analyzer that your TypoScript setup is actually loaded?

And is your TypoScript setup output into HTML in data-cookieman-settings="..."?

@blueamerican
Copy link
Author

the typoscript is loaded.

The setup:

<div id="cookieman-modal"
     data-cookieman-showonce="1"
     data-cookieman-settings="{&quot;groups&quot;:{&quot;mandatory&quot;:{&quot;preselected&quot;:&quot;1&quot;,&quot;disabled&quot;:&quot;1&quot;,&quot;trackingObjects&quot;:[&quot;CookieConsent&quot;,&quot;fe_typo_user&quot;]},&quot;marketing&quot;:{&quot;respectDnt&quot;:&quot;1&quot;,&quot;showDntMessage&quot;:&quot;1&quot;,&quot;trackingObjects&quot;:[&quot;Matomo&quot;]}},&quot;trackingObjects&quot;:{&quot;CookieConsent&quot;:{&quot;show&quot;:{&quot;CookieConsent&quot;:{&quot;duration&quot;:&quot;1&quot;,&quot;durationUnit&quot;:&quot;year&quot;,&quot;type&quot;:&quot;cookie_http+html&quot;,&quot;provider&quot;:&quot;Website&quot;}}},&quot;Matomo&quot;:{&quot;inject&quot;:&quot;            \u003Cscript data-what=\&quot;Matomo\&quot; src=\&quot;\/fileadmin\/js\/cookieman-inject.js\&quot;\u003E\u003C\/script\u003E&quot;,&quot;show&quot;:{&quot;_pk_id&quot;:{&quot;duration&quot;:&quot;13&quot;,&quot;durationUnit&quot;:&quot;months&quot;,&quot;type&quot;:&quot;cookie_http+html&quot;,&quot;provider&quot;:&quot;Matomo&quot;,&quot;htmlCookieRemovalPattern&quot;:&quot;^_pk_id\\.\\d+\\.[a-fA-F0-9]+$&quot;},&quot;_pk_ref&quot;:{&quot;duration&quot;:&quot;6&quot;,&quot;durationUnit&quot;:&quot;months&quot;,&quot;type&quot;:&quot;cookie_http+html&quot;,&quot;provider&quot;:&quot;Matomo&quot;,&quot;htmlCookieRemovalPattern&quot;:&quot;^_pk_ref\\.\\d+\\.[a-fA-F0-9]+$&quot;},&quot;_pk_ses&quot;:{&quot;duration&quot;:&quot;30&quot;,&quot;durationUnit&quot;:&quot;minutes&quot;,&quot;type&quot;:&quot;cookie_http+html&quot;,&quot;provider&quot;:&quot;Matomo&quot;,&quot;htmlCookieRemovalPattern&quot;:&quot;^_pk_ses\\.\\d+\\.[a-fA-F0-9]+$&quot;},&quot;_pk_cvar&quot;:{&quot;duration&quot;:&quot;30&quot;,&quot;durationUnit&quot;:&quot;minutes&quot;,&quot;type&quot;:&quot;cookie_http+html&quot;,&quot;provider&quot;:&quot;Matomo&quot;,&quot;htmlCookieRemovalPattern&quot;:&quot;^_pk_cvar\\.\\d+\\.[a-fA-F0-9]+$&quot;},&quot;_pk_hsr&quot;:{&quot;duration&quot;:&quot;30&quot;,&quot;durationUnit&quot;:&quot;minutes&quot;,&quot;type&quot;:&quot;cookie_http+html&quot;,&quot;provider&quot;:&quot;Matomo&quot;,&quot;htmlCookieRemovalPattern&quot;:&quot;^_pk_hsr\\.\\d+\\.[a-fA-F0-9]+$&quot;}}}}}"
     class="modal fade" tabindex="-1" role="dialog"
>

@blueamerican
Copy link
Author

in the root ts template i include the static template "cookieman"
in the setup section:
<INCLUDE_TYPOSCRIPT: source="FILE: fileadmin/Resources/Typoscript/ext_cookieman.typoscript">

is there a problem with the order of the ts?

@blueamerican
Copy link
Author

blueamerican commented Aug 7, 2020

or is this the error, see empty space:

error1

@blueamerican
Copy link
Author

i removed the empty space:

Matomo":{"inject":"\u003Cscript data-what="Matomo"

what is:
\u003Cscript
?

@jonaseberle
Copy link
Member

Empty space is just empty string. It looks like good JSON to me.
\003C is HTML encoded JSON. It's ok, it's the same here: https://cookieman.d-mind.de/theme-bootstrap4-modal

Can you please try with the default static TypoScript, just included in the site template?

image

We run the exact same configuration (TYPO3 9.5.20, cookieman 2.5.1) on https://cookieman.d-mind.de/, too

@blueamerican
Copy link
Author

with the static template it works

btw: i know another user who has exactly the same problem

@jonaseberle
Copy link
Member

We can try to confirm that the settings are correctly parsed in JavaScript.
Could you enter JSON.parse(document.querySelector('[data-cookieman-settings]').dataset.cookiemanSettings) in a JavaScript console?

It should return a JavaScript object.

image

@jonaseberle
Copy link
Member

I see the problem now. It is in your configuration.

You defined the Tracking Object fe_typo_user in group mandatory, but your settings do not define plugin.tx_cookieman.settings.trackingObjects.fe_typo_user.show.

@jonaseberle
Copy link
Member

You're welcome.

I am sure you can solve that yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants