Package Django pour la gestion du consentement cookies (RGPD/CNIL) — bandeau moderne, admin Django, intégrations GA/GTM/Meta/Matomo/Plausible.
Project description
🍪 xeolux-cookiekit
Package Django de gestion du consentement cookies — RGPD/CNIL ready
Bandeau cookies moderne, configurable depuis l'admin Django, sécurisé par HMAC-SHA256, conforme RGPD/CNIL, avec 11 intégrations tierces prêtes à l'emploi.
Fonctionnalités
- Bandeau + modal préférences — UI moderne 100 % CSS custom properties, sans dépendance JS
- Configurable depuis l'admin Django — zéro code côté settings pour tout sauf
enabled - RGPD/CNIL — analytics opt-in uniquement, durée max 395 jours (13 mois) respectée
- HMAC-SHA256 — cookie signé côté serveur, cookie HttpOnly anti-falsification
- 11 intégrations — GA4, GTM, Meta Pixel, LinkedIn, TikTok, X/Twitter, Matomo, Plausible, Clarity, Hotjar, Crisp
- API JavaScript —
hasConsent(),acceptAll(),rejectAll(), événementxeolux:cookies:updated - Versioning du consentement — le bandeau réapparaît si la version change
- Compatibilité xeolux-cachekit — synchronisation de version optionnelle
- Bridge xeolux-analyticskit — prêt pour intégration future (package séparé)
Sommaire
- Installation
- Configuration rapide
- Intégration dans les templates
- Administration Django
- Intégrations tierces
- API JavaScript
- Personnalisation CSS
- Sécurité cookie HMAC
- Catégories de cookies
- Versioning du consentement
- Compatibilité xeolux-cachekit
- Tests
- Avertissement RGPD/CNIL
Installation
pip install xeolux-cookiekit
Avec support xeolux-cachekit :
pip install "xeolux-cookiekit[cachekit]"
1. Ajouter l'application
# settings.py
INSTALLED_APPS = [
...
"xeolux_cookiekit",
]
2. Appliquer les migrations
python manage.py migrate xeolux_cookiekit
3. Activer le context processor (recommandé)
# settings.py
TEMPLATES = [
{
"OPTIONS": {
"context_processors": [
...
"xeolux_cookiekit.context_processors.cookiekit_config",
],
},
},
]
Configuration rapide
Dans settings.py, une seule ligne suffit :
XEOLUX_COOKIEKIT = {"enabled": True}
Tout le reste (style, textes, intégrations, catégories…) se configure dans l'admin Django.
Intégration dans les templates
Dans votre base.html :
{% load cookiekit_tags %}
<!DOCTYPE html>
<html>
<head>
...
{% cookiekit_head %}
</head>
<body>
{% cookiekit_body %}
...votre contenu...
{% cookiekit_banner %}
</body>
</html>
Script conditionnel par catégorie
{% load cookiekit_tags %}
{% cookiekit_script "analytics" %}
<script>
/* Ce bloc ne s'exécute que si "analytics" est consenti */
myAnalyticsTool.init();
</script>
{% endcookiekit_script %}
Administration Django
Accédez à /admin/xeolux_cookiekit/cookiekitconfig/ pour tout configurer visuellement.
| Section admin | Contenu |
|---|---|
| Général | Activation, version de consentement, durée cookie |
| 🔒 Sécurité du cookie | Signature HMAC-SHA256 (activée par défaut) |
| Apparence | Couleurs, position, layout, ombres, police |
| Textes | Labels des boutons, titres, lien politique de confidentialité |
| Intégrations Google | GA4 (G-xxx), GTM (GTM-xxx) |
| Autres intégrations | Meta, LinkedIn, TikTok, Twitter/X, Matomo, Plausible, Clarity, Hotjar, Crisp |
| Scripts personnalisés | HTML/JS <head> et <body> après consentement |
| CacheKit / Versioning | Synchronisation avec xeolux-cachekit |
| AnalyticsKit | Bridge vers xeolux-analyticskit (futur) |
| Avancé | CSS personnalisé, z-index |
Priorité de configuration
config_source |
Comportement |
|---|---|
admin_fallback_settings (défaut) |
Admin en priorité, fallback sur settings.py |
settings_only |
Ignore l'admin — tout depuis settings.py |
admin_only |
Admin obligatoire — erreur si absent |
Intégrations tierces
Les intégrations sont gérées via le modèle CookieKitIntegration (Admin → Intégrations). Chaque script est injecté uniquement après consentement à la catégorie correspondante. Aucune migration DB nécessaire pour ajouter une intégration.
Analytics
| Intégration | Catégorie | Config JSON |
|---|---|---|
| Google Analytics 4 | analytics |
measurement_id |
| Google Tag Manager | analytics |
container_id |
| Matomo | analytics |
site_id, tracker_url |
| Plausible Analytics | analytics |
domain, script_url |
| Microsoft Clarity | analytics |
project_id |
| Hotjar | analytics |
site_id |
| Mixpanel | analytics |
project_token |
| Amplitude | analytics |
api_key |
| PostHog | analytics |
api_key, host |
| Umami Analytics | analytics |
website_id, script_url |
| Fathom Analytics | analytics |
site_id |
| Segment | analytics |
write_key |
| Heap Analytics | analytics |
app_id |
| FullStory | analytics |
org_id |
| Cloudflare Web Analytics | analytics |
token |
| HubSpot Tracking | analytics |
portal_id |
Marketing
| Intégration | Catégorie | Config JSON |
|---|---|---|
| Meta Pixel | marketing |
pixel_id |
| LinkedIn Insight Tag | marketing |
partner_id |
| TikTok Pixel | marketing |
pixel_id |
| Twitter / X Pixel | marketing |
pixel_id |
| Pinterest Tag | marketing |
tag_id |
| Snapchat Pixel | marketing |
pixel_id |
| Reddit Pixel | marketing |
advertiser_id |
| Quora Pixel | marketing |
pixel_id |
| Brevo Tracker | marketing |
client_key |
Support / Chat
| Intégration | Catégorie | Config JSON |
|---|---|---|
| Crisp Chat | preferences |
website_id |
| Intercom | preferences |
app_id |
| Zendesk Chat | preferences |
key |
| Tidio Chat | preferences |
public_key |
| Freshchat | preferences |
token, host |
Activation depuis l'admin
- Allez dans Admin → Xeolux CookieKit → Intégrations
- Sélectionnez une intégration (toutes sont créées automatiquement au premier
migrate) - Cochez Actif et renseignez le champ Configuration (JSON) :
{"measurement_id": "G-XXXXXXXXXX"}
- Sauvegardez — le script est actif immédiatement
API JavaScript
// Vérifier le consentement d'une catégorie
window.XeoluxCookieKit.hasConsent("analytics"); // true | false
// Lire le consentement complet
window.XeoluxCookieKit.getConsent();
// { version: "1.0.0", updated_at: "...", choices: { necessary: true, analytics: true, ... } }
// Actions utilisateur
window.XeoluxCookieKit.acceptAll();
window.XeoluxCookieKit.rejectAll();
window.XeoluxCookieKit.savePreferences({ analytics: true, marketing: false });
// Interface
window.XeoluxCookieKit.openPreferences();
window.XeoluxCookieKit.closePreferences();
window.XeoluxCookieKit.resetConsent(); // Supprime le cookie, réaffiche le bandeau
// Écouter les changements de consentement
window.addEventListener("xeolux:cookies:updated", (event) => {
const consent = event.detail;
if (consent.choices.analytics) {
// Activer vos outils analytics
}
});
Personnalisation CSS
Le style est piloté par des CSS custom properties (--xck-*) :
:root {
--xck-bg: #111111;
--xck-text: #ffffff;
--xck-primary: #ff6b00;
--xck-primary-text: #ffffff;
--xck-secondary: #2b2b2b;
--xck-secondary-text: #ffffff;
--xck-radius: 14px;
--xck-z-index: 9999;
--xck-shadow: 0 8px 40px rgba(0,0,0,0.45);
--xck-font: system-ui, sans-serif;
}
Toutes les classes CSS sont préfixées xck- pour éviter les conflits :
.xck-banner, .xck-modal, .xck-button, .xck-button--primary, .xck-toggle, .xck-category…
Utilisez le champ CSS personnalisé dans l'admin pour tout surcharger.
Sécurité cookie HMAC
xeolux-cookiekit implémente une stratégie deux cookies :
| Cookie | Accessible JS | Rôle |
|---|---|---|
xeolux_cookie_consent |
✅ Oui | Stocke les choix (version, catégories) |
xeolux_cookie_consent_sig |
❌ Non (HttpOnly) | Signature HMAC-SHA256 — détecte les falsifications |
La signature est calculée avec settings.SECRET_KEY + sel statique via hmac.new(key, payload, sha256). Toute modification manuelle du cookie est détectée côté serveur.
Vérification dans une view Django :
from xeolux_cookiekit.security import get_verified_consent
def my_view(request):
consent = get_verified_consent(request, cookie_name="xeolux_cookie_consent")
if consent and consent.has("analytics"):
# Consentement analytics vérifié et non falsifié
...
Catégories de cookies
Catégories intégrées
| Clé | Label | Requis | Défaut |
|---|---|---|---|
necessary |
Nécessaires | ✅ Oui | ✅ Toujours actif |
analytics |
Mesure d'audience | Non | ❌ Opt-in (CNIL) |
marketing |
Marketing | Non | ❌ Opt-in (CNIL) |
preferences |
Préférences | Non | ❌ Opt-in (CNIL) |
Catégories personnalisées
Le modèle CookieCategory (admin) permet d'ajouter des catégories custom. Elles apparaissent automatiquement dans la modal de préférences.
{% cookiekit_script "ma_categorie_custom" %}
<script>/* activé après consentement */</script>
{% endcookiekit_script %}
Versioning du consentement
Si la consent_version change, le bandeau réapparaît pour tous les utilisateurs.
Via l'admin : champ Version de consentement, ou utilisez l'action "Incrémenter la version (patch)" depuis la liste.
Compatibilité xeolux-cachekit
pip install "xeolux-cookiekit[cachekit]"
Si xeolux_cachekit est installé et que cachekit.sync_cookie_version est activé, la version de consentement est synchronisée avec la version cachekit. Fonctionne en mode dégradé sans cachekit.
Tests
pip install "xeolux-cookiekit[dev]"
pytest
66 tests couvrent : config merge, RGPD/CNIL compliance, singleton admin, HMAC signing, payload validation, falsification detection, analytics bridge.
Changelog
v1.1.0 (2025)
- Nouveau modèle
CookieKitIntegration— remplace les 22 champs individuels d'intégration deCookieKitConfigpar un modèle générique avecJSONField - 30 intégrations (15 nouvelles) : Mixpanel, Amplitude, PostHog, Umami, Fathom, Segment, Heap, FullStory, Cloudflare Web Analytics, HubSpot, Pinterest Tag, Snapchat Pixel, Reddit Pixel, Quora Pixel, Brevo, Intercom, Zendesk Chat, Tidio, Freshchat
- Nouveau fichier
integrations.py— catalogue centralisé + générateurs JS individuels - Ajout d'un admin
CookieKitIntegrationAdminavec aide contextuelle JSON - Auto-création des 30 intégrations au
migrate(toutes désactivées par défaut) - Migrations 0007 (création table) + 0008 (suppression anciens champs)
v1.0.1 (2025)
- Correctif
banner.html(balise<button>manquante — texte "Refuser" affiché en clair) - Catégories auto-créées via signal
post_migrate - Champ
cachekit_version_statusdans l'admin - Suppression des champs redondants
custom_head/body_scripts
v1.0.0 (2025)
- Version initiale : bandeau RGPD, modal préférences, 11 intégrations, HMAC-SHA256, CacheKit bridge
Avertissement RGPD/CNIL
Ce package est un outil technique. Il ne constitue pas un conseil juridique.
La conformité RGPD/CNIL dépend de votre implémentation, de votre politique de confidentialité et de la nature de vos traitements. Consultez la documentation CNIL et un juriste pour votre conformité.
© 2026 Xeolux — Licence MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters