Complete API documentation for Extended Cookie Consent library.
Initialize the cookie consent popup with the provided configuration.
cookieconsent.extended.init(options: Object): EnhancedPopup
| Parameter | Type | Required | Description |
|---|---|---|---|
| options | Object | No | Configuration object for the cookie consent popup |
// Basic initialization
const popup = cookieconsent.extended.init();
// With configuration
const popup = cookieconsent.extended.init({
ui: {
theme: 'dracula',
position: 'center-modal'
},
content: {
header: 'Cookie Notice',
message: 'We use cookies to improve your experience.'
}
});
| Property | Type | Default | Description |
|---|---|---|---|
| ui.theme | String | null | Theme name (e.g., 'dracula', 'github-dark') |
| ui.position | String | 'bottom-right' | Position of the popup |
| ui.animationType | String | 'slide' | Animation type: 'slide', 'fade', 'bounce' |
| ui.showPreferences | Boolean | true | Show category preference controls |
| ui.backdrop | Boolean | false | Show backdrop overlay |
| Property | Type | Default | Description |
|---|---|---|---|
| content.header | String | 'We use cookies' | Popup header text |
| content.message | String | Default message | Main message text |
| content.acceptAll | String | 'Accept All' | Accept all button text |
| content.rejectAll | String | 'Reject All' | Reject all button text |
| content.acceptSelected | String | 'Accept Selected' | Accept selected button text |
Each category object can have the following properties:
| Property | Type | Description |
|---|---|---|
| enabled | Boolean | Whether the category is enabled by default |
| locked | Boolean | Whether the category cannot be disabled (for necessary cookies) |
| name | String | Display name for the category |
| description | String | Description of what this category includes |
Get the current consent status for all categories.
cookieconsent.extended.getConsent(): Object
const consent = cookieconsent.extended.getConsent();
// Returns: { necessary: true, analytics: false, marketing: true }
Check if user has consented to a specific category.
cookieconsent.extended.hasConsent(category: String): Boolean
if (cookieconsent.extended.hasConsent('analytics')) {
// Initialize analytics
gtag('config', 'GA_MEASUREMENT_ID');
}
Get the audit trail of consent records (if enabled).
cookieconsent.extended.getAuditTrail(): Array
Get all available themes.
cookieconsent.extended.getAvailableThemes(): Object
Get themes filtered by type.
cookieconsent.extended.getThemesByType(type: String): Object
| Parameter | Type | Description |
|---|---|---|
| type | String | 'light' or 'dark' |
Get all available position options.
cookieconsent.extended.getAvailablePositions(): Object
Fired when the user's consent status changes.
window.addEventListener('cookieConsentChange', function(event) {
console.log('Consent changed:', event.detail.categories);
console.log('Consent record:', event.detail.record);
});
| Property | Type | Description |
|---|---|---|
| event.detail.categories | Object | Current consent status for all categories |
| event.detail.record | Object | Consent record with timestamp and metadata |
github-light - GitHub's light themematerial-light - Google Material Designtailwind-light - Tailwind CSS stylingbootstrap-light - Bootstrap frameworkant-light - Ant Design systemchakra-light - Chakra UI thememantine-light - Mantine frameworksemantic-light - Semantic UIbulma-light - Bulma CSS frameworkfoundation-light - Foundation frameworkdracula - Popular Dracula themegithub-dark - GitHub's dark modematerial-dark - Material Design darktailwind-dark - Tailwind dark modevscode-dark - VS Code dark themeatom-dark - Atom editor themesublime-dark - Sublime Text colorsnord-dark - Nord color palettediscord-dark - Discord app stylingslack-dark - Slack workspace themenotion-dark - Notion app colors| Position | Description | Use Case |
|---|---|---|
bottom-right |
Bottom right corner | Default, non-intrusive |
bottom-left |
Bottom left corner | Alternative corner position |
bottom-center |
Bottom center | Central bottom positioning |
bottom-bar |
Full-width bottom bar | Prominent notice, mobile-friendly |
top-right |
Top right corner | Above-fold positioning |
top-left |
Top left corner | Alternative top position |
top-center |
Top center | Central top positioning |
top-bar |
Full-width top bar | Immediate visibility |
center |
Center of screen | Maximum attention |
center-modal |
Center with backdrop | Modal-style presentation |
| Callback | Parameters | Description |
|---|---|---|
onAcceptAll |
categories: Object | Called when user accepts all cookies |
onRejectAll |
categories: Object | Called when user rejects all non-essential cookies |
onCategoryToggle |
category: String, enabled: Boolean | Called when a category is toggled |
onPreferencesShow |
- | Called when preferences panel is shown |
onPreferencesHide |
- | Called when preferences panel is hidden |
cookieconsent.extended.init({
callbacks: {
onAcceptAll: function(categories) {
// Enable all tracking
gtag('config', 'GA_MEASUREMENT_ID');
},
onCategoryToggle: function(category, enabled) {
if (category === 'analytics') {
gtag('consent', 'update', {
'analytics_storage': enabled ? 'granted' : 'denied'
});
}
}
}
});
Access utility functions through cookieconsent.extended.utils:
Set a cookie only if the user has consented to the category.
// Only set cookie if analytics is enabled
cookieconsent.extended.utils.setCookieWithCategory(
'analytics_id',
'user123',
'analytics',
{ days: 30 }
);
Get the consented categories from localStorage.
Trigger analytics events for consent actions.