|
| 1 | +# Cookie Consent Implementation |
| 2 | + |
| 3 | +This document describes the cookie consent implementation for Essential C# website to comply with Microsoft Clarity's new consent requirements for EEA, UK, and Switzerland users. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +Starting October 31, 2025, Microsoft Clarity requires explicit consent signals for users from the European Economic Area (EEA), United Kingdom (UK), and Switzerland. This implementation provides a comprehensive solution using Google Consent Mode v2 that works with both Microsoft Clarity and Google Analytics. |
| 8 | + |
| 9 | +## Implementation Details |
| 10 | + |
| 11 | +### Files Modified/Added |
| 12 | + |
| 13 | +1. **`/wwwroot/js/consent-manager.js`** - New consent management system |
| 14 | +2. **`Views/Shared/_Layout.cshtml`** - Updated to integrate consent manager with analytics |
| 15 | +3. **`Views/Home/Privacy.cshtml`** - Enhanced privacy policy page |
| 16 | + |
| 17 | +### Features |
| 18 | + |
| 19 | +- **Automatic Region Detection**: Detects users from EEA/UK/Switzerland using timezone |
| 20 | +- **Google Consent Mode v2**: Unified consent framework for both analytics platforms |
| 21 | +- **Granular Consent**: Separate consent for Analytics and Advertising cookies |
| 22 | +- **Persistent Storage**: Saves consent preferences for 365 days |
| 23 | +- **Responsive Design**: Works on desktop and mobile devices |
| 24 | +- **Accessibility**: Proper ARIA labels and keyboard navigation |
| 25 | + |
| 26 | +### Consent Categories |
| 27 | + |
| 28 | +1. **Essential Cookies** - Always granted (required for functionality) |
| 29 | +2. **Analytics Cookies** - Optional (Google Analytics, Microsoft Clarity) |
| 30 | +3. **Advertising Cookies** - Optional (advertising and remarketing) |
| 31 | + |
| 32 | +### User Experience |
| 33 | + |
| 34 | +For users in EEA/UK/Switzerland: |
| 35 | +1. Cookie banner appears on first visit |
| 36 | +2. Users can Accept All, Reject All, or Customize preferences |
| 37 | +3. Customization shows detailed information about each cookie category |
| 38 | +4. Preferences are saved and respected across visits |
| 39 | +5. Users can change preferences anytime via footer link |
| 40 | + |
| 41 | +For users outside these regions: |
| 42 | +- No banner shown by default |
| 43 | +- Analytics work normally |
| 44 | +- Consent preferences still accessible via footer link |
| 45 | + |
| 46 | +## Technical Integration |
| 47 | + |
| 48 | +### Google Consent Mode v2 |
| 49 | + |
| 50 | +The implementation uses Google's Consent Mode v2 with these consent types: |
| 51 | +- `analytics_storage` |
| 52 | +- `ad_storage` |
| 53 | +- `ad_user_data` |
| 54 | +- `ad_personalization` |
| 55 | +- `functionality_storage` (always granted) |
| 56 | +- `security_storage` (always granted) |
| 57 | + |
| 58 | +### Microsoft Clarity Integration |
| 59 | + |
| 60 | +Clarity consent is managed via the Clarity Consent API: |
| 61 | +```javascript |
| 62 | +clarity('consent', analyticsConsent); |
| 63 | +``` |
| 64 | + |
| 65 | +### Google Analytics Integration |
| 66 | + |
| 67 | +Google Analytics respects consent mode automatically: |
| 68 | +```javascript |
| 69 | +gtag('consent', 'update', consentState); |
| 70 | +gtag('config', 'G-761B4BMK2R'); // Only when consent granted |
| 71 | +``` |
| 72 | + |
| 73 | +## Testing |
| 74 | + |
| 75 | +### Test Parameters |
| 76 | + |
| 77 | +Add `?testConsent=true` to any URL to force consent banner display for testing. |
| 78 | + |
| 79 | +### Verification Steps |
| 80 | + |
| 81 | +1. Visit site from EEA timezone or with test parameter |
| 82 | +2. Verify banner appears |
| 83 | +3. Test Accept All - analytics should activate |
| 84 | +4. Test Reject All - analytics should remain disabled |
| 85 | +5. Test Custom preferences - verify granular control |
| 86 | +6. Check consent persistence across page loads |
| 87 | + |
| 88 | +## Compliance |
| 89 | + |
| 90 | +This implementation ensures compliance with: |
| 91 | +- **GDPR** - Explicit consent before processing personal data |
| 92 | +- **ePrivacy Directive** - Cookie consent requirements |
| 93 | +- **Microsoft Clarity** - New consent enforcement requirements |
| 94 | + |
| 95 | +## Browser Support |
| 96 | + |
| 97 | +- Modern browsers with ES6 support |
| 98 | +- Graceful degradation for older browsers |
| 99 | +- Works without JavaScript (essential functionality only) |
| 100 | + |
| 101 | +## Maintenance |
| 102 | + |
| 103 | +### Adding New Analytics Services |
| 104 | + |
| 105 | +1. Add consent check in initialization code |
| 106 | +2. Update consent manager to include new service |
| 107 | +3. Test consent flow with new service |
| 108 | + |
| 109 | +### Updating Consent Categories |
| 110 | + |
| 111 | +Modify the `consentState` object in `ConsentManager` constructor and update the banner UI accordingly. |
| 112 | + |
| 113 | +## Support |
| 114 | + |
| 115 | +For technical issues or questions about this implementation, please refer to: |
| 116 | +- Microsoft Clarity documentation: https://learn.microsoft.com/en-us/clarity/ |
| 117 | +- Google Consent Mode documentation: https://developers.google.com/tag-platform/gtagjs/consent |
0 commit comments