{"id":5898,"date":"2024-03-11T19:56:14","date_gmt":"2024-03-11T18:56:14","guid":{"rendered":"https:\/\/ekiwi.de\/?p=5898"},"modified":"2024-03-11T19:57:40","modified_gmt":"2024-03-11T18:57:40","slug":"cookieconsent-v3-problems-with-script-management-with-data-category","status":"publish","type":"post","link":"https:\/\/ekiwi.de\/en\/index.php\/5898\/cookieconsent-v3-problems-with-script-management-with-data-category\/","title":{"rendered":"CookieConsent v3: Problems with script management with data-category"},"content":{"rendered":"<p>Scripts were not executed when the cookie category was selected.<\/p>\n<p><!--more--><\/p>\n<p>I have built a cookie banner on two of our websites with the help of the &#8220;<a href=\"https:\/\/github.com\/orestbida\/cookieconsent\">CookieConsent-Script<\/a>&#8220;.<\/p>\n<p>Depending on the selection of categories, certain <a href=\"https:\/\/cookieconsent.orestbida.com\/advanced\/manage-scripts.html\">scripts should be executed<\/a>, e.g. for Matomo or Google Analytics.<\/p>\n<p>However, this did not work. I marked the scripts with the &#8220;data-category&#8221; attribute and also set the &#8220;type&#8221; to &#8220;text\/plain&#8221;, but the selection was not recognised and the script was not executed.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/03\/cookie_1.png\" alt=\"\" width=\"527\" height=\"142\" class=\"alignnone size-full wp-image-5894\" srcset=\"\/wp-content\/uploads\/2024\/03\/cookie_1.png 527w, \/wp-content\/uploads\/2024\/03\/cookie_1-300x81.png 300w\" sizes=\"auto, (max-width: 527px) 100vw, 527px\" \/><\/p>\n<p>The solution was quite simple in the end. It is important that the configuration script or the cookie consent script is only executed at the end or after the scripts. Then it worked.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/03\/cookie_2.png\" alt=\"\" width=\"643\" height=\"165\" class=\"alignnone size-full wp-image-5896\" srcset=\"\/wp-content\/uploads\/2024\/03\/cookie_2.png 643w, \/wp-content\/uploads\/2024\/03\/cookie_2-300x77.png 300w\" sizes=\"auto, (max-width: 643px) 100vw, 643px\" \/><\/p>","protected":false},"excerpt":{"rendered":"<p>Scripts were not executed when the cookie category was selected.<\/p>\n","protected":false},"author":1,"featured_media":4353,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[881,870],"tags":[1026,1025],"class_list":["post-5898","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript-en","category-programming","tag-cookie-en","tag-data-protection-en"],"_links":{"self":[{"href":"https:\/\/ekiwi.de\/en\/index.php\/wp-json\/wp\/v2\/posts\/5898","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ekiwi.de\/en\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ekiwi.de\/en\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ekiwi.de\/en\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ekiwi.de\/en\/index.php\/wp-json\/wp\/v2\/comments?post=5898"}],"version-history":[{"count":0,"href":"https:\/\/ekiwi.de\/en\/index.php\/wp-json\/wp\/v2\/posts\/5898\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ekiwi.de\/en\/index.php\/wp-json\/wp\/v2\/media\/4353"}],"wp:attachment":[{"href":"https:\/\/ekiwi.de\/en\/index.php\/wp-json\/wp\/v2\/media?parent=5898"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ekiwi.de\/en\/index.php\/wp-json\/wp\/v2\/categories?post=5898"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ekiwi.de\/en\/index.php\/wp-json\/wp\/v2\/tags?post=5898"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}