# AdSense Click Fraud Protection - Documentation

## 🛡️ Overview

এই সিস্টেম আপনার ওয়েবসাইটকে invalid clicks এবং fraudulent ad interactions থেকে রক্ষা করে। এটি Google AdSense policies মেনে চলে এবং আপনার account নিরাপদ রাখে।

## ✨ Features

### 1. Click Rate Limiting
- **Per Minute**: সর্বোচ্চ ২টি click (60 সেকেন্ডে)
- **Per Hour**: সর্বোচ্চ ৫টি click (1 ঘণ্টায়)
- **Per Day**: সর্বোচ্চ ১০টি click (দৈনিক)
- **Minimum Gap**: দুটি click এর মধ্যে কমপক্ষে ৫ সেকেন্ড বিরতি

### 2. Bot Detection
Automatic bot detection করে এই জিনিসগুলো check করে:
- WebDriver detection (automated browsers)
- Headless browser detection
- Suspicious user agents
- Plugin availability
- Screen dimensions
- Timing patterns
- Touch support validation
- CDP (Chrome DevTools Protocol) detection

### 3. Behavioral Analysis
- **Mouse Movement Tracking**: সাধারণ মানুষের mouse movement pattern চেক করে
- **Click Position Analysis**: একই জায়গায় বারবার click detect করে
- **Pattern Recognition**: Suspicious clicking patterns চিহ্নিত করে
- **User Fingerprinting**: প্রতিটি visitor এর unique fingerprint তৈরি করে

### 4. Real-time Protection
- Click attempt block করা হয় instant
- Visual warning message দেখায়
- Activity log রাখে সব suspicious behavior এর
- Automatic daily reset (মধ্যরাতে)

## 📊 How It Works

### Protection Flow:
```
User Click on Ad
    ↓
Check if bot? → Yes → Block + Log
    ↓ No
Check rate limits → Exceeded → Block + Warn
    ↓ OK
Check behavior patterns → Suspicious → Block + Log
    ↓ Clean
Allow Click + Record
```

### Data Storage:
```javascript
localStorage:
  - adClickData: Click counts, timestamps
  - adClickLogs: Suspicious activity logs
  - rateLimit_[fingerprint]: Per-user rate limiting
```

## 🎯 Usage

### Installation (Already Done ✅)
Protection scripts automatically loaded on all pages:
- `bot-detection.js` - Bot detection engine
- `ad-click-protection.js` - Main protection system

### Admin Panel Features

#### 1. Protection Statistics Dashboard
- **Total Clicks Today**: আজকের valid clicks
- **Blocked Clicks**: Block করা invalid clicks
- **Protection Status**: সিস্টেম চালু আছে কিনা
- **Bot Score**: Visitor এর bot probability (0-100)

#### 2. Activity Logs
- সব suspicious clicks এর log
- Timestamp, URL, click counts
- User agent information
- Pattern details

#### 3. Management Options
- **Refresh Stats**: Latest data reload করে
- **View Logs**: Detailed activity log দেখায়
- **Reset Data**: সব protection data clear করে

## 🚨 Warning System

যখন invalid click detect হয়:
```
⚠️ Warning
Too many ad clicks detected. 
Please wait before clicking again.
```

এই warning:
- Red background with 95% opacity
- 5 seconds পর automatic hide
- Top-right corner এ থাকে
- Slide-in animation সহ

## 📝 AdSense Policy Compliance

এই protection system নিশ্চিত করে:

### ✅ DO's (যা করা হয়)
- Rate limiting সব levels এ
- Bot detection and blocking
- Suspicious pattern monitoring
- Activity logging
- User behavior tracking
- Automatic protection

### ❌ DON'Ts (যা করা হয় না)
- Click না করার জন্য encourage করা (✅ শুধু rate limit)
- Ad এর design নকল করা (✅ শুধু protection)
- Click incentives দেওয়া (✅ কোনো incentive নেই)
- Ad কে interact করা (✅ শুধু monitor)

## 🔧 Configuration

### Limits Customization (বর্তমান settings):
```javascript
config: {
    maxClicksPerMinute: 2,
    maxClicksPerHour: 5,
    maxClicksPerDay: 10,
    minTimeBetweenClicks: 5000,  // 5 seconds
    clickCooldown: 30000,         // 30 seconds
    suspiciousPatternThreshold: 3
}
```

### বদলানোর জন্য:
`assets/js/ad-click-protection.js` file এ `this.config` object edit করুন।

## 📈 Analytics Integration

Automatically sends events to Google Analytics (যদি থাকে):
```javascript
// Valid clicks
gtag('event', 'valid_ad_click', {...})

// Suspicious activity
gtag('event', 'suspicious_ad_click', {...})
```

## 🔍 Monitoring

### Check Protection Status:
```javascript
// Browser console এ
window.adClickProtection.getStats()

// Returns:
{
    totalClicks: 5,
    dailyClicks: 5,
    blockedClicks: 2,
    protectionActive: true
}
```

### Check Bot Detection:
```javascript
const detector = new BotDetection();
detector.getDetails()

// Returns:
{
    score: 15,
    isBot: false,
    checks: {...},
    confidence: 15
}
```

## 🎨 Admin Panel Access

1. Open: `admin/index.html`
2. Scroll down to "🛡️ Click Fraud Protection" section
3. View real-time statistics
4. Click "View Activity Logs" to see details
5. Click "Refresh Stats" to update data

## 🧪 Testing

### Test Invalid Click Protection:
1. কোনো game page open করুন
2. Ad placeholder এ দ্রুত click করুন (2+ times in 5 seconds)
3. Warning message দেখা যাবে
4. Admin panel এ blocked count বাড়বে

### Test Bot Detection:
1. Browser console open করুন
2. Type: `new BotDetection().getDetails()`
3. Score দেখুন (normal user = 0-30)

## 📱 Mobile Support

Protection সব devices এ কাজ করে:
- Touch events tracking
- Mobile-specific patterns
- Responsive warning messages
- Cross-browser compatibility

## 🔐 Security Features

1. **Client-side Protection**: Fast, no server needed
2. **LocalStorage**: Data locally stored, secure
3. **Fingerprinting**: Unique user identification
4. **Pattern Learning**: Adaptive detection
5. **Daily Reset**: Fresh start every day

## 💡 Best Practices

### For Site Owners:
1. ✅ Admin panel regularly check করুন
2. ✅ Blocked clicks monitor করুন
3. ✅ Logs review করুন weekly
4. ✅ Limits adjust করুন যদি প্রয়োজন হয়

### For Users:
- Normal browsing এ কোনো বাধা নেই
- Genuine clicks allow করা হবে
- শুধু excessive clicking block হবে
- 5 second gap maintain করলে কোনো সমস্যা নেই

## ⚙️ Advanced Configuration

### Custom Protection Rules:
`assets/js/ad-click-protection.js` এ customize করতে পারেন:

```javascript
// Example: Stricter limits
maxClicksPerMinute: 1,  // 1 click per minute only
maxClicksPerDay: 5,     // 5 clicks per day max

// Example: Relaxed limits
maxClicksPerMinute: 3,
minTimeBetweenClicks: 3000  // 3 seconds gap
```

## 🐛 Troubleshooting

### Problem: Protection not working
**Solution**: Check browser console for errors, reload page

### Problem: Valid clicks blocked
**Solution**: 
- Wait 5 seconds between clicks
- Check admin panel for high bot score
- Clear protection data using "Reset" button

### Problem: Stats not updating
**Solution**: 
- Click "Refresh Stats" button
- Check localStorage permissions
- Clear browser cache

## 📞 Support

যদি কোনো সমস্যা হয়:
1. Admin panel এ logs check করুন
2. Browser console দেখুন
3. Protection data reset করে দেখুন
4. Limits adjust করুন প্রয়োজন মতো

## 🎯 Next Steps

1. ✅ Protection installed and active
2. ⏳ Monitor for 1-2 weeks
3. ⏳ Review logs regularly
4. ⏳ Adjust limits based on traffic
5. ⏳ Check AdSense reports for improvements

---

## 🌟 Summary

**আপনার website এখন পুরোপুরি protected!**

✅ Click fraud detection active  
✅ Bot blocking enabled  
✅ Rate limiting implemented  
✅ Activity logging working  
✅ Admin monitoring available  
✅ AdSense policy compliant  

**Protection automatically চলবে সব pages এ. কোনো additional setup লাগবে না!**
