# GDPR Compliance for A1AI Chatbots

## Overview

The A1AI plugin now includes built-in GDPR (General Data Protection Regulation) compliance functionality that allows website owners to implement proper consent mechanisms for AI chatbot interactions.

## Features

- **Per-Chatbot Configuration**: Each chatbot can have its own GDPR consent settings
- **Customizable Consent Text**: Administrators can customize the consent message
- **Local Storage Persistence**: User consent is remembered using browser localStorage
- **Frontend Consent Overlay**: Professional consent dialog that appears before chat access
- **Decline Option**: Users can decline consent and the chatbot will be hidden
- **Works with Both Shortcode and Global Chatbots**: GDPR compliance works for all chatbot types

## Setup

### 1. Enable GDPR Compliance

1. Go to **A1AI > Chatbots** in your WordPress admin
2. Click **Edit** on any chatbot
3. Go to the **Messages** tab
4. Check the **"Enable GDPR Compliance Consent Mechanism"** checkbox
5. Customize the **GDPR Consent Text** if needed
6. Click **Update Chatbot**

### 2. Default Consent Text

The default consent text is:
```
By clicking "I Agree", you consent to the use of AI-powered chat services and acknowledge that your conversations may be processed to provide you with assistance. You can withdraw your consent at any time by closing this chat.
```

### 3. Customizing Consent Text

You can customize the consent text to include:
- Specific information about data processing
- Contact details for data protection inquiries
- Information about data retention policies
- User rights under GDPR

## How It Works

### Frontend Behavior

1. **First Visit**: When a user visits a page with a GDPR-enabled chatbot, they see a consent overlay
2. **Consent Dialog**: The overlay displays your custom consent text with "I Agree" and "Decline" buttons
3. **User Choice**:
   - **I Agree**: User can access the chatbot, consent is stored in localStorage
   - **Decline**: Chatbot is hidden, no consent is stored
4. **Subsequent Visits**: If user previously agreed, the chatbot works normally. If they declined, it remains hidden

### Technical Implementation

#### Storage
- Consent is stored in browser localStorage with key: `a1ai_gdpr_consent_{chatbot_id}`
- Values: `"true"` for consent, `"false"` for decline, or `null` for no decision

#### Frontend Components
- **Consent Overlay**: Modal dialog with consent text and buttons
- **JavaScript Handler**: Manages consent state and chatbot access
- **CSS Styling**: Professional, responsive design

#### Admin Interface
- **Checkbox Control**: Enable/disable GDPR compliance per chatbot
- **Text Area**: Customizable consent message
- **Dynamic UI**: Consent text field shows/hides based on checkbox state

## GDPR Compliance Features

### 1. Explicit Consent
- Users must actively click "I Agree" to provide consent
- No pre-ticked boxes or implied consent
- Clear explanation of what they're consenting to

### 2. Right to Withdraw
- Users can decline consent
- Declining hides the chatbot completely
- Users can change their mind by clearing browser data

### 3. Transparency
- Clear explanation of data processing
- Customizable consent text for specific use cases
- Information about AI processing

### 4. Data Minimization
- Only processes data after explicit consent
- No data collection without consent
- Consent is stored locally (no server-side tracking)

## Customization

### Styling the Consent Overlay

The consent overlay uses these CSS classes:
```css
.a1ai-gdpr-overlay          /* Main overlay container */
.a1ai-gdpr-content          /* Content box */
.a1ai-gdpr-text             /* Consent text area */
.a1ai-gdpr-buttons          /* Button container */
.a1ai-gdpr-agree            /* Agree button */
.a1ai-gdpr-decline          /* Decline button */
```

### JavaScript Functions

Available functions for custom implementations:
```javascript
// Check if user has consented
A1AIChatbot.hasGDPRConsent(container)

// Set consent status
A1AIChatbot.setGDPRConsent(container, true/false)

// Set up GDPR functionality
A1AIChatbot.setupGDPRConsent(container)
```

## Legal Considerations

### Recommended Consent Text Elements

Consider including these elements in your consent text:

1. **Purpose**: Why you're collecting data
2. **Processing**: How AI processes conversations
3. **Retention**: How long data is kept
4. **Rights**: User rights under GDPR
5. **Contact**: How to exercise rights
6. **Withdrawal**: How to withdraw consent

### Example Enhanced Consent Text

```
By clicking "I Agree", you consent to the use of AI-powered chat services provided by [Company Name]. 

Your conversations will be processed by artificial intelligence to provide you with assistance and support. This may include:
- Storing conversation history for service improvement
- Using AI to generate responses to your questions
- Analyzing conversation patterns to improve our service

Your data will be retained for [X] days and you have the right to:
- Access your personal data
- Request deletion of your data
- Withdraw consent at any time
- Contact us at [email] for data protection inquiries

You can withdraw your consent by closing this chat or contacting us directly.
```

## Troubleshooting

### Common Issues

1. **Consent not remembered**: Check if localStorage is enabled in the browser
2. **Overlay not showing**: Verify GDPR is enabled in chatbot settings
3. **Styling issues**: Check for CSS conflicts with your theme

### Debug Information

Enable browser developer tools to see:
- Consent status in localStorage
- JavaScript console for any errors
- Network tab for AJAX requests

## Best Practices

1. **Clear Language**: Use simple, clear language in consent text
2. **Specific Information**: Be specific about data processing
3. **Easy Withdrawal**: Make it easy for users to withdraw consent
4. **Regular Review**: Review and update consent text regularly
5. **Legal Review**: Have legal counsel review your consent text

## Support

For issues with GDPR compliance:
1. Check browser console for JavaScript errors
2. Verify localStorage is working
3. Test with different browsers
4. Contact plugin support with specific details 