GDPR Cookie consent plugin is a go-to solution to achieve GDPR compliance for your site. The script blocker services incorporated in this plugin allows users to optionally block the script rendered from pre-defined third-party services as per the user’s consent. This can be done either via the automatic script blocker or by manually adding scripts. Both these solutions are server based, where the page request is expected to hit the server first for script blocking/unblocking services to take effect.
However, in certain cases, these server based solutions may not serve the purpose due to various reasons like extreme cache or conflict with third party plugins and so on. Here the pages will be served based on the cached content and the request will not actually reach the server. Therefore the blocking/unblocking may not behave as expected with the above solution. This can now be overcome by using a client side script blocking/unblocking service which will do the job irrespective of where it is being served from(server or cache).
The function that primarily achieves this is
CookieLawInfo_Accept_Callback(), which is triggered when the user registers their consent. The
if (CLI.consent.non_necessary) checks if the consent has been received for the non-necessary category and excecutes the script entailing it and likewise for the
- If the category slug is a hyphenated word, then it has to be replaced by an underscore; for e.g, if you have a category slug: non-necessary, you should replace the hyphen by an underscore and use as follows: