sandstorm / Sandstorm.CookiePunch

Neos Package for content-first consent management built on top of klaro.js.
MIT License
5 stars 3 forks source link

feature? JS Callbacks #11

Closed paavo closed 2 years ago

paavo commented 2 years ago

First: thanks for this nice package 👏

Is there a "planned way" to listen to Events in Javascript? For example: I'd like to fire some lazyloading events after a User accepted the inline cookie-notice for an iFrame Integration.

In the Klaro Config i've found a callback:

callback: function(consent, service) {
    console.log(
        'User consent for service ' + service.name + ': consent=' + consent
    );
},
paavo commented 2 years ago

Overriding Sandstorm.CookiePunch:Config could work 🤔 But everything will be quoted "

prototype(Sandstorm.CookiePunch:Config) {
    consent {
        callback = "function(consent, service) {console.log('User consent for service ' + service.name + ': consent=' + consent);}'"
fheinze commented 2 years ago

Hey, I have thought about that too ;) but have not decided on adding this functionality as Klaro.js already provides an API for this using a watcher -> https://heyklaro.com/docs/api/js_api.

However you feature request feels like a more convenient way of reacting to a consent. I would probably look for a callback method on the window and just call it if it exists or maybe throw an event. This way an integrator does not need to write JS as a string ;)

For me it would be interesting to know what you think about the Klaro API.

Cheers

paavo commented 2 years ago

Thanks for your reply @fheinze Looks like i missed the fact that a Klaro.js watcher already exist 🙈 I think think im fine with the Klaro JS API watcher 🤷