Developer integration & JavaScript API
Reopen preferences
Add a normal link to a footer or policy page:
<a href="#cookiewp-edit">Edit cookie preferences</a>
You can also call window.CookieWP.open() after the CookieWP API has loaded.
Gate an external script
Replace an optional script’s executable markup with inert markup. Do not leave an active src attribute:
<script type="text/plain"
data-cookiewp-category="statistics"
data-cookiewp-src="https://example.com/analytics.js"></script>
Replace the example URL with your provider’s script. Use the category matching its purpose. Inline optional code can use the same type and category attributes without a source URL.
Register a callback
After CookieWP has initialized, register code that should run once permission is available:
window.CookieWP.register('statistics', function () {
// Load or initialize your analytics service here.
});
Each registered callback runs once per page when its category is allowed. Registering is not the same as executing; put the actual loader inside the callback. Integrate initialization order explicitly rather than dropping a call before CookieWP is available.
Read and observe consent
window.CookieWP.getConsent();
window.CookieWP.hasConsent('marketing');
document.addEventListener('cookiewp:consent', function (event) {
console.log(event.detail);
});
getConsent() returns a copy of the current category flags. The event is dispatched on document when consent is notified. Read the current state when installing a listener so you do not rely on catching an earlier event.
window.CookieWP.revoke() saves necessary-only preferences and may reload the page if optional consent was previously granted. It is a state-changing action, not a read method.