Blocking scripts and embeds
A script that has already run cannot be taken back. So Cookie Consent holds things before they start, and lets each one go once the visitor allows its category. There are four ways something waits:
- Pixel Tracking tags wait on their own. See Pixel Tracking and consent.
- Google tags read Google Consent Mode. See Google Consent Mode v2.
- Embeds (YouTube, Vimeo, maps, music and social posts) are caught by the plugin. See Categories.
- Anything else waits when you mark it by hand, as below. With Cookie Consent Pro, 45 known services are held automatically.
Hold a script by hand
Section titled “Hold a script by hand”Change the script’s type to text/plain and add data-brl-consent with the category. The browser does not run a text/plain script, and Cookie Consent starts it once the category is allowed.
<script type="text/plain" data-brl-consent="marketing"> // your tracking code</script><script type="text/plain" data-brl-consent="statistics" data-brl-consent-src="https://example.com/tracker.js"></script>The categories you can use are statistics (Analytics), marketing, preferences and embedded_video (External media). A held script with no category waits for Marketing.
Held scripts start in page order, so a library loads before the code that calls it.
Hold an iframe by hand
Section titled “Hold an iframe by hand”Put the address in data-brl-consent-src instead of src, and set the category in data-brl-consent:
<iframe data-brl-consent-src="https://example.com/widget" data-brl-consent="embedded_video"></iframe>A held iframe gets a short note with a button that opens the choices. A held address is given only to an iframe, image, video, audio or source element, and only over https.
What happens when the visitor answers
Section titled “What happens when the visitor answers”- Held scripts and iframes for the allowed categories start straight away, without a reload.
- If the visitor later withdraws consent, a script that already ran keeps running until the next page. Turn on Reload after the choice changes (Behaviour tab) if you use scripts that cannot be stopped without a reload.
Automatic blocking (Pro)
Section titled “Automatic blocking (Pro)”With Cookie Consent Pro, the Blocking tab holds 45 known services until the visitor allows their category, without changes to your code. Pages are checked as they are sent: scripts and frames from known services are held, and start when their category is allowed. Necessary services are never held, so payments and spam checks keep working.
- Hold known services until consent: the main switch.
- Found on this site: the services seen in your pages so far, each with the category it Waits for. Change the category if you use the service differently.
- Your own rules: a domain, optionally with a path, such as
widget.example.comorcdn.example.com/track, and a category. Anything loaded from it waits. Subdomains are included. - From the cookie scan, Block it turns a finding into a rule.
To keep one script running, add data-no-block to its tag. To look at a page without blocking, add ?brl_consent_noblock=1 to its address while you are signed in.
See Cookie Consent Pro.
For developers
Section titled “For developers”Cookie Consent publishes the visitor’s answer in the browser and in PHP, so other code can ask.
In the browser:
window.brlConsent.hasConsent('marketing')returns true or false.window.brlConsent.getState()returns the saved choice.window.brlConsent.rejectAll()andwindow.brlConsent.openPreferences().wp_has_consentgives the same answer, for code written for the WP Consent API.- Every change fires a
brl_consent_changedevent ondocument. A choice the visitor makes firesbrl_consent_saved, once per choice, never on a page load.
In PHP, through filters:
| Filter | Answer |
|---|---|
brl_consent_has_consent |
true or false for a category |
brl_consent_provider |
brainrune-consent while the banner is active |
brl_consent_categories |
the categories offered, keyed by slug |
brl_consent_preferences_control |
the HTML for a button that reopens the choices |
The choice is stored in one first-party cookie, brl_consent, with the categories allowed, the policy version and the time of the choice.