### Install Nuxt Cookie Control Module Source: https://github.com/dargmuesli/nuxt-cookie-control/blob/main/README.md Use nuxi to add the cookie-control module to your Nuxt project. ```bash npx nuxi@latest module add cookie-control ``` -------------------------------- ### Cookie Definition Example Source: https://github.com/dargmuesli/nuxt-cookie-control/blob/main/README.md Define individual cookies with their properties, including translatable names and descriptions. Use short IDs for bandwidth efficiency. ```javascript { description: { en: 'This cookie stores preferences.' }, id: 'p', // use a short cookie id to save bandwidth and prefixes to separate isPreselected: false // `true` is not GDPR compliant! This flag does not enable any cookies, it only preselects the cookie's modal toggle. The default is `false`. name: { en: 'Preferences' // you always have to specify a cookie name (in English) }, links: { 'https://example.com/privacy': 'Privacy Policy', 'https://example.com/terms': 'Terms of Service', }, src: 'https://example.com/preferences/js?id=', targetCookieIds: ['xmpl_a', 'xmpl_b'], } ``` -------------------------------- ### Module Options Configuration Source: https://github.com/dargmuesli/nuxt-cookie-control/blob/main/README.md Configure the behavior and appearance of the cookie consent bar and modal. Customize positions, colors, cookie settings, and more. ```javascript // Position of cookie bar. // 'top-left', 'top-right', 'top-full', 'bottom-left', 'bottom-right', 'bottom-full' barPosition: 'bottom-full', // Switch to toggle if clicking the overlay outside the configuration modal closes the modal. closeModalOnClickOutside: true, // Component colors. // If you want to disable colors set colors property to false. colors: { barBackground: '#000', barButtonBackground: '#fff', barButtonColor: '#000', barButtonHoverBackground: '#333', barButtonHoverColor: '#fff', barTextColor: '#fff', checkboxActiveBackground: '#000', checkboxActiveCircleBackground: '#fff', checkboxDisabledBackground: '#ddd', checkboxDisabledCircleBackground: '#fff', checkboxInactiveBackground: '#000', checkboxInactiveCircleBackground: '#fff', controlButtonBackground: '#fff', controlButtonHoverBackground: '#000', controlButtonIconColor: '#000', controlButtonIconHoverColor: '#fff', focusRingColor: '#808080', modalBackground: '#fff', modalButtonBackground: '#000', modalButtonColor: '#fff', modalButtonHoverBackground: '#333', modalButtonHoverColor: '#fff', modalOverlay: '#000', modalOverlayOpacity: 0.8, modalTextColor: '#000', modalUnsavedColor: '#fff', }, // The cookies that are to be controlled. // See detailed explanation further down below! cookies: { necessary: [], optional: [], } // The milliseconds from now until expiry of the cookies that are being set by this module. cookieExpiryOffsetMs: 1000 * 60 * 60 * 24 * 365, // one year // Names for the cookies that are being set by this module. cookieNameIsConsentGiven: 'ncc_c', cookieNameCookiesEnabledIds: 'ncc_e', // Options to pass to nuxt's useCookie cookieOptions: { path: '/', sameSite: 'strict', }, // Switch to toggle the "accept necessary" button. isAcceptNecessaryButtonEnabled: true, // Switch to toggle the button that opens the configuration modal. isControlButtonEnabled: true, // Switch to toggle the concatenation of target cookie ids to the cookie description. isCookieIdVisible: false, // Switch to toggle the inclusion of this module's css. // If css is set to false, you will still be able to access your color variables. isCssEnabled: true, // Switch to toggle the css variables ponyfill. isCssPonyfillEnabled: false, // Switch to toggle the separation of cookie name and description in the configuration modal by a dash. isDashInDescriptionEnabled: true, // Switch to toggle the blocking of iframes. // This can be used to prevent iframes from adding additional cookies. isIframeBlocked: false, // Switch to toggle the modal being shown right away, requiring a user's decision. isModalForced: false, // "Decline all" in the modal removes all cookies by default (which will re-open the cookie bar). // Set this to true to decline all optional cookies and accept necessary cookies. declineAllAcceptsNecessary: false, // The locales to include. locales: ['en'], // Translations to override. localeTexts: { en: { save: 'Remember', } } ``` -------------------------------- ### Initialize Analytics Based on Enabled Cookies Source: https://github.com/dargmuesli/nuxt-cookie-control/blob/main/README.md Use the useCookieControl composable in a client plugin to initialize services like Google Analytics only if their corresponding cookie is enabled. ```typescript // plugins/analytics.client.ts // example: initialization based on enabled cookies const cookieControl = useCookieControl() if (cookieControl.cookiesEnabledIds.value.includes('google-analytics')) { initGoogleAnalytics() // placeholder for your custom initialization } ``` -------------------------------- ### Configure Nuxt Cookie Control Module Source: https://github.com/dargmuesli/nuxt-cookie-control/blob/main/README.md Configure the module in your nuxt.config.js file, either with typed or untyped module options. ```javascript // nuxt.config.js modules: [ '@dargmuesli/nuxt-cookie-control' ], cookieControl: { // typed module options } ``` ```javascript // or modules: [ ['@dargmuesli/nuxt-cookie-control', { // untyped module options }] ] ``` -------------------------------- ### Set Cookie Control Locale Source: https://github.com/dargmuesli/nuxt-cookie-control/blob/main/README.md Configure the language of the cookie control interface using the 'locale' prop. The available locales are listed in the documentation. ```html ``` -------------------------------- ### Custom Control Button with SVG Source: https://github.com/dargmuesli/nuxt-cookie-control/blob/main/README.md Use the 'controlButton' slot to replace the default control button with a custom SVG icon. ```html ``` -------------------------------- ### Basic Usage of CookieControl Component Source: https://github.com/dargmuesli/nuxt-cookie-control/blob/main/README.md Include the CookieControl component in your app.vue and access its state and methods using useCookieControl. ```html ``` -------------------------------- ### Custom Iframe Slot in CookieIframe Component Source: https://github.com/dargmuesli/nuxt-cookie-control/blob/main/README.md Define custom content to display when iframes are blocked by the module using the 'iframe' slot in the CookieIframe component. ```html ``` -------------------------------- ### Custom Bar Slot in CookieControl Component Source: https://github.com/dargmuesli/nuxt-cookie-control/blob/main/README.md Customize the content of the cookie consent bar using the 'bar' slot. Allows for custom titles, descriptions, and links. ```html ``` -------------------------------- ### Custom Modal Slot in CookieControl Component Source: https://github.com/dargmuesli/nuxt-cookie-control/blob/main/README.md Customize the content of the cookie consent modal using the 'modal' slot. Enables custom titles and descriptions within the modal. ```html ``` -------------------------------- ### Custom Cookie Slot in CookieControl Component Source: https://github.com/dargmuesli/nuxt-cookie-control/blob/main/README.md Customize the display of individual cookies within the modal using the 'cookie' slot. Access cookie details like name, description, and target IDs. ```html ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.