astro-cookieconsent icon indicating copy to clipboard operation
astro-cookieconsent copied to clipboard

Can't configure callbacks

Open docapi opened this issue 2 years ago • 7 comments

The config doesn't accept functions, so it's not possible to define the callback "onFirstAction", "onAccept" and "onChange".

e.g.

onFirstAction: function(){
    console.log('onFirstAction fired');
},

docapi avatar Oct 26 '23 13:10 docapi

Same problem

nikolas-nelson avatar Dec 13 '23 21:12 nikolas-nelson

Are you passing the function directly in the Astro config?

That's not possible as far as I'm aware, but I haven't tried to be honest. I'll find some time the next days to play around with this. Probably we need to build some sort of runtime hook system to work with those handlers. I'll think about this.

cngJo avatar Jan 29 '24 20:01 cngJo

If you have functions in your cookie configuration file, JSON.stringify will omit them. So maybe you have to add a special convert job which skips the JSON.stringify-part for functions.

Or do you see an other way to inject the callbacks?

docapi avatar Jan 30 '24 11:01 docapi

http://www.eslinstructor.net/jsonfn/

Flaflo avatar Sep 18 '24 23:09 Flaflo

Sorry for the long silence ... my current idea to solve this, is to load the config from the window object, which you could then define in your main Layout or in a component.

This would remove the configuration from the Astro config into plain JS / TS code, which then allows you to work with callbacks as expected.

IMO, this would be the cleanest solution, do you think this approach would solve your issues?

cngJo avatar Oct 24 '24 20:10 cngJo