michnhokn / kirby-cookie-banner

A Cookie Consent Modal for Kirby
MIT License
67 stars 9 forks source link

Implement client side "real time" conditional loading of consented scripts #11

Closed prookie closed 1 year ago

prookie commented 2 years ago

Hi!

I implemented client side conditional loading of scripts. The method is known from different cookie consent services like Usercentrics, CookieFirst and others (see https://docs.usercentrics.com/#/direct-implementation-guide or https://support.cookiefirst.com/hc/en-us/articles/360011566698--Change-website-s-scripts-to-comply-with-the-GDPR).

To use it, replace (or add if missing) type="text/plain" and add data-cookie-feature="feature-identifier" to your script tags that depend on user consent. No logic in PHP is needed. When the user gives consent for feature feature-identifier, the scripts then gets loaded and executed. This check is also done on page load. If consent for a script gets withdrawn, the page will be reloaded to remove all code of those affected scripts immediately and completely.

This new feature is a completely optional addition, the plugins still works as before.

Oh and i also installed Parcel as a local project dependency (as I and maybe others are not using it otherwise).

michnhokn commented 2 years ago

Thank you @prookie for you nice work! I will have a look at your PR the next days and then also release a new "bigger" version with some other adjustments.

prookie commented 2 years ago

You're welcome. I implemented the extension for a client project, so why not give something back for your work on this plugin.

If you have any questions on the method or implementation, just ask.

michnhokn commented 1 year ago

Hey @prookie,

Thanks again for the PR. I've decided not to implement it as I'm not currently in a position to maintain a more complex plugin. Still, your work is greatly appreciated and I'll mention this PR on the wiki for people who might want this kind of functionality.