|
64 | 64 | <h4 class="font-medium text-base-content mb-3"> |
65 | 65 | Choose your preferences: |
66 | 66 | </h4> |
67 | | - <div class="grid grid-cols-1 md:grid-cols-3 gap-4"> |
| 67 | + <div class="grid grid-cols-1 md:grid-cols-2 gap-4"> |
68 | 68 | <div class="flex items-start gap-3"> |
69 | 69 | <input |
70 | 70 | type="checkbox" |
|
106 | 106 | type="checkbox" |
107 | 107 | id="functional-cookies" |
108 | 108 | class="checkbox checkbox-sm" |
109 | | - checked |
110 | | - disabled |
111 | 109 | /> |
112 | 110 | <div> |
113 | 111 | <label |
114 | 112 | for="functional-cookies" |
115 | | - class="font-medium text-sm cursor-pointer opacity-60" |
116 | | - >Functional Cookies (Required)</label |
| 113 | + class="font-medium text-sm cursor-pointer" |
| 114 | + >Functional Cookies</label |
117 | 115 | > |
118 | 116 | <p class="text-xs text-base-content/60 mt-1"> |
119 | 117 | Essential for website functionality and your preferences |
120 | 118 | </p> |
121 | 119 | </div> |
122 | 120 | </div> |
| 121 | + <div class="flex items-start gap-3"> |
| 122 | + <input |
| 123 | + type="checkbox" |
| 124 | + id="personalization-cookies" |
| 125 | + class="checkbox checkbox-sm" |
| 126 | + /> |
| 127 | + <div> |
| 128 | + <label |
| 129 | + for="personalization-cookies" |
| 130 | + class="font-medium text-sm cursor-pointer" |
| 131 | + >Personalization Cookies</label |
| 132 | + > |
| 133 | + <p class="text-xs text-base-content/60 mt-1"> |
| 134 | + Remember your preferences and customize your experience |
| 135 | + </p> |
| 136 | + </div> |
| 137 | + </div> |
123 | 138 | </div> |
124 | 139 | <div class="flex justify-end gap-2 mt-4"> |
125 | 140 | <button id="cancel-customize" class="btn btn-ghost btn-sm"> |
|
159 | 174 | const consent = this.getCookieConsent(); |
160 | 175 |
|
161 | 176 | if (!consent) { |
162 | | - // Apply default consent (all granted) |
163 | | - const defaultConsent = { |
164 | | - analytics: true, |
165 | | - advertising: true, |
166 | | - functional: true, |
167 | | - timestamp: Date.now(), |
168 | | - }; |
169 | | - this.applyConsent(defaultConsent); |
| 177 | + // Show banner for first-time users - no default consent applied |
| 178 | + this.showBanner(); |
170 | 179 | } else { |
171 | 180 | // Apply existing preferences |
172 | 181 | this.applyConsent(consent); |
173 | 182 | } |
174 | 183 |
|
175 | | - // Always setup event listeners (for customize functionality) |
| 184 | + // Always setup event listeners |
176 | 185 | this.setupEventListeners(); |
177 | 186 | } |
178 | 187 |
|
|
198 | 207 | acceptBtn.addEventListener("click", () => { |
199 | 208 | const consent = { |
200 | 209 | analytics: true, |
201 | | - advertising: true, // Always true for AdSense |
202 | | - functional: true, // Always true for functionality |
| 210 | + advertising: true, // Always true for AdSense (mandatory) |
| 211 | + functional: true, |
| 212 | + personalization: true, |
203 | 213 | timestamp: Date.now(), |
204 | 214 | }; |
205 | 215 | this.saveConsent(consent); |
|
208 | 218 | }); |
209 | 219 | } |
210 | 220 |
|
211 | | - // Reject all cookies (but advertising and functional remain enabled) |
| 221 | + // Reject non-essential cookies (advertising remains enabled) |
212 | 222 | const rejectBtn = document.getElementById("reject-cookies"); |
213 | 223 | if (rejectBtn) { |
214 | 224 | rejectBtn.addEventListener("click", () => { |
215 | 225 | const consent = { |
216 | | - analytics: false, // Only reject analytics |
217 | | - advertising: true, // Keep ads enabled |
218 | | - functional: true, // Keep functional enabled |
| 226 | + analytics: false, |
| 227 | + advertising: true, // Always true for AdSense (mandatory) |
| 228 | + functional: false, |
| 229 | + personalization: false, |
219 | 230 | timestamp: Date.now(), |
220 | 231 | }; |
221 | 232 | this.saveConsent(consent); |
|
270 | 281 | const analyticsCheckbox = document.getElementById( |
271 | 282 | "analytics-cookies" |
272 | 283 | ) as HTMLInputElement; |
| 284 | + const advertisingCheckbox = document.getElementById( |
| 285 | + "advertising-cookies" |
| 286 | + ) as HTMLInputElement; |
| 287 | + const functionalCheckbox = document.getElementById( |
| 288 | + "functional-cookies" |
| 289 | + ) as HTMLInputElement; |
| 290 | + const personalizationCheckbox = document.getElementById( |
| 291 | + "personalization-cookies" |
| 292 | + ) as HTMLInputElement; |
273 | 293 |
|
274 | 294 | const consent = { |
275 | 295 | analytics: analyticsCheckbox?.checked ?? false, |
276 | 296 | advertising: true, // Always true for AdSense (mandatory) |
277 | | - functional: true, // Always true for functionality (mandatory) |
| 297 | + functional: functionalCheckbox?.checked ?? false, |
| 298 | + personalization: personalizationCheckbox?.checked ?? false, |
278 | 299 | timestamp: Date.now(), |
279 | 300 | }; |
280 | 301 | this.saveConsent(consent); |
|
294 | 315 | } |
295 | 316 |
|
296 | 317 | applyConsent(consent: any) { |
297 | | - // Handle Google AdSense consent (always enabled for mandatory advertising) |
| 318 | + // Handle advertising consent (always enabled for AdSense) |
298 | 319 | this.enableAdSense(); |
299 | 320 |
|
300 | | - // Handle analytics |
| 321 | + // Handle analytics consent |
301 | 322 | if (consent.analytics) { |
302 | 323 | this.enableAnalytics(); |
303 | 324 | } else { |
304 | 325 | this.disableAnalytics(); |
305 | 326 | } |
306 | 327 |
|
307 | | - // Functional cookies are always enabled for basic functionality |
308 | | - this.enableFunctional(); |
| 328 | + // Handle functional consent |
| 329 | + if (consent.functional) { |
| 330 | + this.enableFunctional(); |
| 331 | + } else { |
| 332 | + this.disableFunctional(); |
| 333 | + } |
| 334 | + |
| 335 | + // Handle personalization consent |
| 336 | + if (consent.personalization) { |
| 337 | + this.enablePersonalization(); |
| 338 | + } else { |
| 339 | + this.disablePersonalization(); |
| 340 | + } |
309 | 341 | } |
310 | 342 |
|
311 | 343 | enableAdSense() { |
|
349 | 381 | } |
350 | 382 |
|
351 | 383 | enableFunctional() { |
352 | | - // Functional cookies are always enabled |
| 384 | + // Enable functional cookies |
353 | 385 | if (typeof gtag !== "undefined") { |
354 | 386 | gtag("consent", "update", { |
355 | 387 | functionality_storage: "granted", |
356 | 388 | security_storage: "granted", |
357 | 389 | }); |
358 | 390 | } |
359 | 391 | } |
| 392 | + |
| 393 | + disableFunctional() { |
| 394 | + // Disable functional cookies |
| 395 | + if (typeof gtag !== "undefined") { |
| 396 | + gtag("consent", "update", { |
| 397 | + functionality_storage: "denied", |
| 398 | + security_storage: "denied", |
| 399 | + }); |
| 400 | + } |
| 401 | + } |
| 402 | + |
| 403 | + enablePersonalization() { |
| 404 | + // Enable personalization cookies |
| 405 | + if (typeof gtag !== "undefined") { |
| 406 | + gtag("consent", "update", { |
| 407 | + personalization_storage: "granted", |
| 408 | + }); |
| 409 | + } |
| 410 | + } |
| 411 | + |
| 412 | + disablePersonalization() { |
| 413 | + // Disable personalization cookies |
| 414 | + if (typeof gtag !== "undefined") { |
| 415 | + gtag("consent", "update", { |
| 416 | + personalization_storage: "denied", |
| 417 | + }); |
| 418 | + } |
| 419 | + } |
360 | 420 | } |
361 | 421 |
|
362 | 422 | // Initialize cookie consent when DOM is loaded |
|
0 commit comments