WebToffee Logo
  • Home
  • Plugins
  • Blog
  • Documentation
  • Support
Login
0

  • Overview
    • Plugin set up
  • GDPR
    • Getting Started
      • Get GDPR Compliant
    • Add and Categorise Cookies
      • Troubleshoot cookie scanner
      • Add cookie manually
      • Disable cookie categories by default
      • Using cookie scanner
    • Auto-block cookies with Script Blocker
      • Compatibility with WP cache plugins
      • Configuration
      • Add custom script blocker
      • Block scripts at client side
      • Block services in Google Tag Manager separately
      • Check script blocking
    • Create Privacy Policy Page
      • Policy generator
    • Customize Settings Pop up
      • Adding cookie settings link to footer
      • Alter colour of toggle button
      • Change cookie category order in settings popup
      • Adding Custom columns into the Audit Table
      • Display category wise cookie list
    • Customize Cookie Notice
      • Category checkboxes on cookie banner
      • Geo-target cookie message bar
      • Customize banner using CSS
      • Accept consent on scroll/delay
      • Customize templates
      • Hide the cookie bar on selected pages
      • Pre-defined templates
      • Shortcodes for banner
    • Multilingual Support
      • Translate using Polylang
      • Multilingual compatibility for Necessary Category
      • Translate using WPML
      • Translate using qTranslate
      • Multilanguage compatibility for privacy policy page
    • Advanced Topics
      • Modify duration of consent
      • Access/Block site based on consent
      • Show/hide 'Privacy and Cookie Policy' tab
  • CCPA
    • Getting Started
      • Get CCPA Compliant
  • Third-Party Compatibility
    • Plugins/Themes
  • FAQ
    • Frequently asked questions
  • Changelog
    • Version 2.3.7

Documentation/GDPR Cookie Consent/Blocking scripts at the client side (Javascript)

Blocking scripts at the client side (Javascript)

Last updated on August 14, 2021

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 example below will show you exactly how the scripts can be controlled at the client-side (via Javascript). However you need to know that the corresponding services should be disabled from the automatic script blocker; for e.g, if you plan to use a client-side script blocking service for the Facebook pixel you must ensure that this service is disabled under the Script blocker (automatic or extended via filters).

Javascript helper class function can be inserted into the active theme’s header.php. The code snippet below assumes that you have configured the Hotjar script under the Non-necessary and GA script under the Analytics category. Let us see how to disable these scripts via the Javascript code.

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 executes the script entailing it and likewise for the if (CLI.consent.analytics).

Note:

  1. The scripts entered as a javascript helper class must be explicitly disabled from the script blocker screen. You can enable or disable the entire script blocker third party services all at once or disable individually using the toggle from the front end.
Script blocker enable or disable
Script blocker enable or disable
  1. While using the javascript code, insert the cookie/script category slug in the if condition; e.g, category analytics should be used in the following manner if(CLI.consent.analytics) 
  2. 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: if(CLI.consent.non_necessary).
  • Was this article helpful?
  • Yes, thanks!Not really

This article posted in Auto-block cookies with Script Blocker, Documentation, GDPR Cookie Consent, Knowledge Base and tagged check script blocking, client-side, GDPR Cookie Consent, Script blocking

Written by

Shesna

Shesna is a technical content writer for WebToffee. She is familiar in working closely with the SMEs to break down complex technical information into a concise, easy to understand manner.

Comments (10)

  1. Vasco

    February 8, 2022

    The function CookieLawInfo_Accept_Callback is not called without a page reload. How can we configure it in such a way?
    Thanks.

    Reply
    • Mark

      Mark

      February 16, 2022

      Hi Vasco,

      Greetings from Webtoffee!

      This function will run upon clicking ACCEPT button without a page reload. Feel free to revert if any issues.

      Reply
  2. Philip Myhill

    Philip Myhill

    August 13, 2021

    “The code snippet below” suggests there should be a snippet of code from the header.php file but I can’t see it. Is there something missing from this page?

    Reply
    • Shesna

      Shesna

      August 14, 2021

      Hi Philip,
      We regret for the inconveniences caused. Due to a technical glitch, the code was not rendered on the page. We have updated the same. Thank you.

      Reply
  3. Olivier

    May 18, 2021

    Hi, is it possible to block other plugins through a PHP wp webhook? (The plugin is not shown in the blockable plugins in your plugin)
    E.g. I use this chat-plugin which should be disabled unless the visitor gives his cookie consent.
    If so, where can I find the documentation to do this?
    Thanks! Olivier

    Reply
    • Mark

      Mark

      May 21, 2021

      Hi Oliver,

      Our premium version plugin supports a filter to add more script to script blocker. Please find the filter and sample code here.

      Reply
  4. ElsaV

    May 7, 2021

    Hello,
    Is it possible to prevent the deactivation of the necessary cookies category?
    Thank you for your return,
    E.

    Reply
    • Mark

      Mark

      May 8, 2021

      Hi,

      By default, the necessary category is strictly enabled and therefore it cannot be deactivated. Make sure that the category slug of the necessary category is set to ‘necessary’.

      Reply
  5. Coding Nut

    August 13, 2019

    Can you please explain what a “Category” is? What’s the difference between “Non Necessary” and “Necessary”

    Reply
    • Mark

      Mark

      August 14, 2019

      Hi,

      Refer the article link here to know more about the default categories.

      Reply

Got any query? Please leave a comment or reach out to our support

Cancel reply

Your email address will not be published. Required fields are marked *

We develop awesome WordPress plugins & WooCommerce extensions to help build successful online businesses.

© 2021 WebToffee. All rights reserved.

Our plugins

  • GDPR Cookie Consent
  • PDF Invoices & Packings Slips
  • Product Import Export Plugin
  • User & Customer Import Export
  • Import Export Suite
  • Sequential Order Numbers
  • Smart Coupons for WooCommerce
  • URL Coupons for WooCommerce
  • PayPal Express Checkout
  • Stripe Payment Gateway
  • Subscriptions for Woocommerce
  • Product Catalog Sync for Facebook
  • PrintNode for PDF Invoices
  • Order, coupon, subscriptions for WooCommerce
  • WordPress Backup and Migration
View more +

Get Started

  • Plugins
  • Testimonials
  • Affiliates
  • We're hiring

Help & Support

  • Documentation
  • Documentation (Basic)
  • FAQ
  • Support

Company

  • Terms & Conditions
  • Privacy Policy
  • Refund policy
  • Support policy
  • License Activation

© 2021 WebToffee. All rights reserved.

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies. However you may visit Cookie Settings to provide a controlled consent.
Cookie settingsACCEPT
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of the basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website, to store user preferences and provide you with content and advertisements that are relevant. Such cookies will be stored on your browser but only upon procuring consent.

You will also have the option to opt-out of these cookies should you want to. But opting out of some of these cookies may have an effect on your browsing experience as per the descriptions elucidated against the respective categories below.

Necessary
Always Enabled

The cookies defines under this category are absolutely essential for the website to function. Hence they are loaded by default irrespective if user consent.

CookieDescription
PHPSESSIDThis cookie is native to PHP applications. The cookie is used to store and identify a users' unique session ID for the purpose of managing user sessions on the website. The cookie is a session cookie and is deleted when all the browser windows are closed.
viewed_cookie_policyThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not a user has consented to the use of cookies. It does not store any personal data.
Analytics

Analytics cookies help us understand how our visitors interact with the website. It helps us understand the number of visitors, where the visitors are coming from, and the pages they navigate. The cookies collect this data and are reported anonymously.

CookieDescription
_gaThis cookie is installed by Google Analytics. The cookie is used to calculate visitor, session, campaign data and keep track of site usage for the site's analytics report. The cookies store information anonymously and assigns a randomly generated number to identify unique visitors.
_gat_gtagIdentification code of website for tracking visits.
_gidThis cookie is installed by Google Analytics. The cookie is used to store information on how visitors use a website and helps in creating an analytics report of how the website is doing. The data collected including the number visitors, the source where they have come from, and the pages visited in an anonymous form.
_hjidHotjar cookie. This cookie is set when the customer first lands on a page with the Hotjar script. It is used to persist the random user ID, unique to that site on the browser. This ensures that behavior in subsequent visits to the same site will be attributed to the same user ID.
_hjIncludedInSampleThis cookie is set to let Hotjar know whether that visitor is included in the sample which is used to generate heatmaps, funnels, recordings, etc.
has_recent_activityThis cookie is used to signal to the code repository website if the user has browsed other website resources during the current session.
tk_aiGathers information for our own first-party analytics tool about how our services are used. A collection of internal metrics for user activity and is used to improve user experience.
tk_lrThis cookie is set by the JetPack plugin on sites using WooCommerce. This is a referral cookie used for analyzing referrer behavior for Jetpack.
tk_orThis cookie is set by the JetPack plugin on sites using WooCommerce. This is a referral cookie used for analyzing referrer behavior for Jetpack.
tk_qsGathers information for our own first-party analytics tool about how our services are used. A collection of internal metrics for user activity and is used to improve user experience.
tk_r3dThe cookie is installed by JetPack. Used for the internal metrics for user activities to improve user experience.
Advertisement

Advertisement cookies help us provide our visitors with relevant ads and marketing campaigns.

CookieDescription
_fbpThis cookie is set by Facebook to deliver advertisements when they are on Facebook or on a digital platform powered by Facebook advertising after visiting this website.
frThe cookie is set by Facebook to show relevant advertisements to the users and measure and improve the advertisements. The cookie also tracks the behavior of the user across the web on sites that have Facebook Pixel or Facebook social plugin.
Preferences

Preference cookies are used to store user preferences to provide them with content that is customized accordingly. This includes the language of the website or the location of the visitor.

CookieDescription
_gh_sessThis cookie is used to preserve users' states across page requests.
Save & Accept