Skip to content

kikkopy/adgate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AdGate

Robust anti-adblock solution for modern websites. Lightweight, undetectable, and effective.

npm version npm downloads License Size JavaScript


πŸš€ Installation

CDN (unpkg)

<script src="https://unpkg.com/adgate/js/lib.js"></script>

npm

npm install adgate

Import in your project:

import "adgate/js/lib.js";

πŸ” Why AdGate?

Most anti-adblock solutions are easily bypassed or detected. AdGate uses 8 advanced detection methods with async processing, smart timeouts, and self-protection to ensure your content stays protected.

New in v2.0:

  • βœ… Async/await architecture
  • βœ… Promise-based detection
  • βœ… Configurable sensitivity
  • βœ… Whitelist support
  • βœ… Theme customization
  • βœ… Bot detection
  • βœ… Performance optimized

⚑ Quick Setup

Basic Integration

<script src="https://unpkg.com/adgate/js/lib.js"></script>

Advanced Configuration

<script>
window.AdGateConfig = {
  sensitivity: 'high',
  theme: 'dark',
  whitelist: ['localhost']
};
</script>
<script src="https://unpkg.com/adgate/js/lib.js"></script>

πŸ›  Configuration Options

window.AdGateConfig = {
  // Detection sensitivity
  sensitivity: 'medium',        // 'low', 'medium', 'high'
  
  // Retry interval in milliseconds
  retryInterval: 30000,         // Default: 30 seconds
  
  // Domains to skip detection
  whitelist: ['localhost', 'dev.example.com'],
  
  // UI theme
  theme: 'dark'                 // 'light' or 'dark'
};

Sensitivity Levels

Level Description Detection Rate Performance
low Basic detection only ~70% Fastest
medium Balanced approach ~85% Optimal
high All methods enabled ~95% Slower

πŸ” Detection Methods

Network Tests

  • Ad server connectivity
  • Resource loading failures
  • Fetch API monitoring

DOM Analysis

  • Hidden element detection
  • CSS property analysis
  • Style injection tests

Performance Tests

  • DOM manipulation timing
  • Script execution delays
  • Resource loading speed

Advanced Detection

  • Mutation observer tracking
  • Browser extension scanning
  • Web worker blocking tests
  • Error event monitoring

🌍 Browser Support

βœ… Chrome 60+ βœ… Firefox 55+ βœ… Safari 12+ βœ… Edge 79+ βœ… Mobile browsers βœ… IE11 (limited)


πŸ“¦ Integration Examples

Basic HTML

<!DOCTYPE html>
<html>
<head>
  <title>My Website</title>
</head>
<body>
  <!-- Your content -->
  <script src="https://unpkg.com/adgate/js/lib.js"></script>
</body>
</html>

WordPress

function add_adgate() {
    wp_enqueue_script('adgate', 'https://unpkg.com/adgate/js/lib.js', array(), '2.0.0', true);
    
    // Add configuration
    wp_add_inline_script('adgate', '
        window.AdGateConfig = {
            sensitivity: "high",
            theme: "dark",
            whitelist: ["' . $_SERVER['HTTP_HOST'] . '/wp-admin"]
        };
    ', 'before');
}
add_action('wp_enqueue_scripts', 'add_adgate');

React/Next.js

import { useEffect } from 'react';

function MyApp() {
  useEffect(() => {
    // Configuration
    window.AdGateConfig = {
      sensitivity: 'medium',
      theme: 'light'
    };
    
    // Load script
    const script = document.createElement("script");
    script.src = "https://unpkg.com/adgate/js/lib.js";
    script.async = true;
    document.body.appendChild(script);
    
    return () => {
      document.body.removeChild(script);
    };
  }, []);

  return <div>Your app content</div>;
}

Vue.js

<template>
  <div id="app">
    <!-- Your content -->
  </div>
</template>

<script>
export default {
  mounted() {
    window.AdGateConfig = {
      sensitivity: 'high',
      retryInterval: 25000
    };
    
    const script = document.createElement('script');
    script.src = 'https://unpkg.com/adgate/js/lib.js';
    document.head.appendChild(script);
  }
}
</script>

🎨 Customization

Theme Options

// Dark theme (default)
window.AdGateConfig = { theme: 'dark' };

// Light theme
window.AdGateConfig = { theme: 'light' };

Whitelist Configuration

window.AdGateConfig = {
  whitelist: [
    'localhost',
    'dev.example.com',
    '192.168.1.100'
  ]
};

Development Mode

// Skip detection in development
window.AdGateConfig = {
  whitelist: ['localhost', '127.0.0.1'],
  sensitivity: 'low'
};

πŸ“Š Analytics Integration

Google Analytics 4

// Add after AdGate script
window.addEventListener('adblock-detected', function() {
  gtag('event', 'adblock_detected', {
    event_category: 'AdGate',
    event_label: 'Blocked Content'
  });
});

Custom Analytics

window.AdGateConfig = {
  onDetect: function(method) {
    // Your analytics code
    analytics.track('Adblock Detected', {
      method: method,
      timestamp: Date.now()
    });
  }
};

🐞 Troubleshooting

Script not working?

  1. Check browser console for errors
  2. Verify script loads after DOM
  3. Test in incognito mode
  4. Check Content Security Policy rules

Too many false positives?

window.AdGateConfig = {
  sensitivity: 'low',           // Reduce sensitivity
  retryInterval: 60000,         // Increase retry interval
  whitelist: ['your-domain.com'] // Add to whitelist
};

Performance issues?

window.AdGateConfig = {
  sensitivity: 'medium',        // Use medium sensitivity
  retryInterval: 45000         // Increase retry interval
};

Development Environment

// Disable in development
if (location.hostname === 'localhost') {
  window.AdGateConfig = { whitelist: ['localhost'] };
}

πŸ”§ Advanced Usage

Conditional Loading

// Only load on specific pages
if (window.location.pathname.includes('/premium-content/')) {
  window.AdGateConfig = { sensitivity: 'high' };
  
  const script = document.createElement('script');
  script.src = 'https://unpkg.com/adgate/js/lib.js';
  document.head.appendChild(script);
}

Custom Event Handling

// Listen for detection events
document.addEventListener('adblock-status', function(e) {
  if (e.detail.detected) {
    console.log('Adblock detected via:', e.detail.method);
    // Your custom logic here
  }
});

πŸ›‘ Best Practices

Performance

  • Load AdGate after critical content
  • Use appropriate sensitivity levels
  • Consider user experience impact

User Experience

  • Provide clear instructions
  • Offer alternative access methods
  • Respect user privacy choices

Development

  • Test across different browsers
  • Use whitelist in development
  • Monitor false positive rates

Legal Compliance

  • Inform users about ad requirements
  • Provide opt-out mechanisms where required
  • Follow local privacy regulations

🀝 Contributing

PRs welcome! Please test thoroughly across browsers before submitting.

Development Setup

git clone https://github.com/kikkopy/adgate.git
cd adgate
npm install
npm test

πŸ“œ License

MIT License. Free for personal and commercial use.


Created by kikkopy

About

Protect your website from adblockers

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published