duncanmcclean / cookie-notice

A simple, lightweight cookie consent widget for your Statamic site.
https://statamic.com/addons/duncanmcclean/cookie-notice
Other
6 stars 9 forks source link

consent groups not being parsed in scripts #81

Closed cstilstra closed 3 months ago

cstilstra commented 3 months ago

Description

I'm having some trouble upgrading to v9.0.0. Long story short what I'm seeing is that the consent widget shows up on the page, but clicking the 'Save Preferences' button seems to do nothing. Looking at the console I'm seeing a couple of JSON errors, the first one indicating that a JSON.parse call is encountering an unexpected end of data, and the second that window.CookieNotice is not defined.

After looking at the generated html and the addon's view/vendor/cookie-notice/scripts.antlers.html I'm finding a discrepancy. In the scripts antlers file we have the two following lines:

let COOKIE_NAME = '{{ cookie_name }}'
let consentGroups = JSON.parse('{{ groups | json }}')

whereas in my final html the same two lines look like so:

let COOKIE_NAME = ''
let consentGroups = JSON.parse('')

It is the 'JSON.parse' call in the second line of the html that is causing the first error that I see in the console. When I search the github repo for the addon, I see no definition of the variable 'groups'. Interestingly, I do see 'cookie_name' defined in CookieNoticeTag, but this is in the widget function rather than the scripts function. I'm thinking that during script initialization the cookie name and consent groups are not being set, causing the JSON.parse call to fail, causing window.CookieNotice to not get defined.

For the record, I have one GTM script defined.

Also, I am running all of this in my dev environment. I have not yet purchased a license for Cookie Notice.

Any thoughts on this?

Steps to reproduce

Require Cookie Notice as a Composer dependency: composer require duncanmcclean/cookie-notice

Publish the addon's configuration file: php artisan vendor:publish --tag=cookie-notice-config

Add the Cookie Notice tags to your layout(s). Make sure the {{ cookie_notice:scripts }} tag is in the and the {{ cookie_notice:widget }} tag is near the top of the

Restart laravel app, clear and warm statamic cache, dump statamic static page cache, run npm run dev (or production, or whatever)

Load site's homepage, check some consent checkboxes and click 'Save Preferences'

observe the page do nothing

Environment

Environment

Application Name: CMSBcom

Laravel Version: 10.48.10

PHP Version: 8.3.6

Composer Version: 2.5.4

Environment: local

Debug Mode: ENABLED

URL: cmsbcom.test

Maintenance Mode: OFF

Cache

Config: CACHED

Events: NOT CACHED

Routes: NOT CACHED

Views: CACHED

Drivers

Broadcasting: log

Cache: redis

Database: mysql

Logs: daily

Mail: smtp

Queue: sync

Session: file

Livewire

Livewire: v3.4.12

Statamic

Addons: 9

Sites: 1

Stache Watcher: Disabled

Static Caching: half

Version: 5.0.2 PRO

Statamic Addons

aryehraber/statamic-captcha: 1.11.0

duncanmcclean/cookie-notice: 9.0.0

jonassiewertsen/statamic-live-search: 2.1.1

jonassiewertsen/statamic-livewire: 3.3.1

rias/statamic-redirect: 3.7.1

spatie/statamic-responsive-images: 5.0.0

statamic-rad-pack/runway: 7.0.0

statamic/eloquent-driver: 4.0.0

statamic/seo-pro: 6.0.1

Statamic Eloquent Driver

Asset Containers: file

Assets: file

Blueprints: file

Collection Trees: file

Collections: file

Entries: eloquent

Forms: file

Global Sets: file

Global Variables: file

Navigation Trees: file

Navigations: file

Revisions: file

Taxonomies: file

Terms: file

cstilstra commented 3 months ago

Well, after completely removing the addon and then reinstalling it everything seems to be working just fine. I'm going to close this issue.

mgtcampbell commented 3 months ago

@duncanmcclean I am getting this error even after removing and re-installing the package.

Note - what is slightly different for me from OP is that I am trying to migrate from doublethreedigital/cookie-notice - is it possible somehow it's loading the old code into {{ cookie_notice:scripts }}

image
mgtcampbell commented 3 months ago

In case anyone else has this issue - I fixed it by deleting the following directory:

/resources/views/vendor/cookie-notice which was still in my setup from an older version and seems like it was getting in the way of correctly setting some config stuff that gets passed to the javascript.

All seems to be working fine now.