# Fetch Config
Source: https://docs.ad-unblock.com/api-reference/fetch-config
Fetch AdUnblock latest configuration
# Configuration API Reference
The AdUnblock Configuration API provides access to the latest JavaScript configuration files needed for ad blocker detection on your website.
## Base URL
```
https://public.adunblocker.com
```
## Authentication
This API endpoint is publicly accessible and does not require authentication.
## Caching
The API responses are cached for optimal performance and support standard HTTP caching headers for efficient client-side caching.
## Server Tag Configuration
### Get JavaScript Configuration
Retrieve the latest JavaScript files needed for ad blocker detection.
```bash cURL theme={null}
curl -X GET https://public.adunblocker.com/api/vendor_scripts
```
```javascript JavaScript theme={null}
const response = await fetch("https://public.adunblocker.com/api/vendor_scripts");
const scripts = await response.json();
```
```python Python theme={null}
import requests
response = requests.get('https://public.adunblocker.com/api/vendor_scripts')
scripts = response.json()
```
#### Response
```json theme={null}
["https://cdn.example.com/detection-script.js"]
```
#### Response Format
The response is a JSON array containing JavaScript file URLs for ad blocker detection as strings.
#### Response Headers
| Header | Description |
| --------------- | ------------------------------------------------- |
| `Content-Type` | `application/json` |
| `ETag` | Entity tag for caching validation |
| `Last-Modified` | Timestamp when the configuration was last updated |
#### Usage Example
Once you fetch the configuration, you can dynamically load the JavaScript files:
```javascript theme={null}
// Fetch configuration
const scripts = await fetch(
"https://public.adunblocker.com/api/vendor_scripts"
).then((response) => response.json());
// Load the JavaScript files
scripts.forEach((scriptUrl) => {
const script = document.createElement("script");
script.src = scriptUrl;
script.async = true;
document.head.appendChild(script);
});
```
#### Caching Recommendations
* The API supports standard HTTP caching headers
* Implement conditional requests using `If-None-Match` header with ETag
* Cache responses locally for better performance
* Check for updates periodically (e.g., every hour)
```javascript theme={null}
// Example with conditional request
const etag = localStorage.getItem("config-etag");
const headers = etag ? { "If-None-Match": etag } : {};
const response = await fetch("https://public.adunblocker.com/api/vendor_scripts", {
headers,
});
if (response.status === 304) {
// Use cached configuration
console.log("Configuration unchanged");
} else {
// Update cache
const scripts = await response.json();
localStorage.setItem("config-etag", response.headers.get("ETag"));
localStorage.setItem("config-data", JSON.stringify(scripts));
}
```
## Valid Script Sources (Deprecated)
This endpoint is deprecated and will be removed in a future version. Please
use the `/api/vendor_scripts` endpoint instead.
### Get Valid Script Sources
Retrieve a list of valid JavaScript source URLs for ad blocker detection.
```bash cURL theme={null}
curl -X GET https://config.adunblocker.com/valid_script_sources.json
```
```javascript JavaScript theme={null}
const response = await fetch(
"https://config.adunblocker.com/valid_script_sources.json"
);
const sources = await response.json();
```
```python Python theme={null}
import requests
response = requests.get('https://config.adunblocker.com/valid_script_sources.json')
sources = response.json()
```
#### Response
```json theme={null}
["https://cdn.example.com/detection-script.js"]
```
#### Response Format
The response is a JSON array containing valid JavaScript source URLs as strings.
#### Response Headers
| Header | Description |
| --------------- | ------------------------------------------------- |
| `Content-Type` | `application/json` |
| `ETag` | Entity tag for caching validation |
| `Last-Modified` | Timestamp when the configuration was last updated |
#### Migration Guide
If you're currently using this endpoint, migrate to the new `/api/vendor_scripts` endpoint:
```javascript theme={null}
// Old (deprecated)
const sources = await fetch(
"https://config.adunblocker.com/valid_script_sources.json"
).then((response) => response.json());
// New (recommended)
const scripts = await fetch(
"https://public.adunblocker.com/api/vendor_scripts"
).then((response) => response.json());
// scripts is already an array, no need to access .js property
```
# Getting Started
Source: https://docs.ad-unblock.com/get-started
Start recovering your lost ad revenue in a few simple steps
# Getting Started with Ad Unblock
Start recovering your lost ad revenue in a few simple steps
## Dashboard-Guided Integration
The Ad Unblock dashboard provides personalized, step-by-step instructions for your specific setup.
## Quick Start Guide
Sign up for an Ad Unblock account to access the dashboard and all features.
[Register Now](https://ad-unblock.com/signup)
Once logged in, add your website to the dashboard to receive a unique verification code.
**Dashboard → Add Site**
The dashboard provides customized integration steps for your specific platform. Simply follow these instructions to integrate Ad Unblock.
* Platform-specific guides
* Custom verification code
* One-click verification
### Ready to get started?
Sign up for a free trial and start recovering your ad revenue today.
Get started with your free trial today
Get personalized help from our team
# Express
Source: https://docs.ad-unblock.com/guides/express
Express middleware for script loading and injection with TypeScript support
A powerful Express middleware for server-side script loading and injection. Load external scripts from remote JSON endpoints with caching, security, and flexible integration options. Built with TypeScript for full type safety.
## Installation
```bash theme={null}
npm install @adunblock/server-tag-express
```
Every rendered ``)
.join("\n");
res.send(`${scriptTags}...`);
});
```
## Configuration Options
| Option | Type | Default | Description |
| ------------------ | ------------------ | --------------- | --------------------------------------- |
| `remoteUrl` | `string` | **Required** | URL to fetch script configuration from |
| `cacheInterval` | `number` | `300` | Cache duration in seconds |
| `injectIntoHtml` | `boolean` | `true` | Auto-inject scripts into HTML responses |
| `injectPosition` | `string` | `''` | Where to inject scripts in HTML |
| `scriptAttributes` | `ScriptAttributes` | `{async: true}` | Additional attributes for script tags |
| `onError` | `function` | `undefined` | Custom error handler function |
| `shouldInject` | `function` | `() => true` | Conditional injection logic |
## Advanced Configuration
```typescript theme={null}
import type { ServerTagMiddlewareOptions } from "@adunblock/server-tag-express";
const config: ServerTagMiddlewareOptions = {
remoteUrl: "https://public.adunblocker.com/api/vendor_scripts",
cacheInterval: 600, // 10 minutes
injectIntoHtml: true,
injectPosition: "",
scriptAttributes: {
defer: true,
"data-source": "server-tag",
},
shouldInject: (req, res) => {
// Don't inject scripts on API routes
return !req.path.startsWith("/api/");
},
onError: (error, req, res) => {
console.error("ServerTag error:", error.message);
// Optional: send error to monitoring service
},
};
app.use(serverTagMiddleware(config));
```
## Route-Specific Configuration
Apply ServerTag to specific routes with different configurations:
```typescript theme={null}
// Global middleware
app.use(
serverTagMiddleware({
remoteUrl: "https://public.adunblocker.com/api/vendor_scripts",
})
);
// Route-specific middleware
app.get(
"/special",
serverTagMiddleware({
remoteUrl: "https://public.adunblocker.com/api/vendor_scripts",
cacheInterval: 60, // 1 minute cache
scriptAttributes: { defer: true },
}),
(req, res) => {
res.render("special-page");
}
);
```
## API Reference
### `serverTagMiddleware(options)`
Main middleware function that adds ServerTag functionality to Express apps.
**Parameters:**
* `options` (ServerTagMiddlewareOptions): Configuration options
**Returns:** Express middleware function
### `injectScripts(html, scripts, attributes, position)`
Helper function to manually inject scripts into HTML strings.
**Parameters:**
* `html` (string): HTML string to modify
* `scripts` (string\[]): Array of script URLs
* `attributes` (ScriptAttributes): Script tag attributes
* `position` (string): Where to inject (default: `''`)
**Returns:** Modified HTML string
### Type Definitions
```typescript theme={null}
interface ServerTagConfig {
cacheInterval?: number;
timeout?: number;
retries?: number;
retryDelay?: number;
}
interface ScriptAttributes {
async?: boolean;
defer?: boolean;
type?: string;
[key: string]: string | boolean | number | undefined;
}
interface ServerTagMiddlewareOptions extends ServerTagConfig {
remoteUrl: string;
injectIntoHtml?: boolean;
injectPosition?: string;
scriptAttributes?: ScriptAttributes;
onError?: (error: Error, req: Request, res: Response) => void;
shouldInject?: (req: Request, res: Response) => boolean;
}
```
## Error Handling
ServerTag includes robust error handling with custom error types:
```typescript theme={null}
import {
ServerTagError,
NetworkError,
ValidationError,
TimeoutError,
} from "@adunblock/server-tag-express";
app.use(
serverTagMiddleware({
remoteUrl: "https://public.adunblocker.com/api/vendor_scripts",
onError: (error, req, res) => {
if (error instanceof NetworkError) {
console.error("Network error:", error.message);
} else if (error instanceof ValidationError) {
console.error("Validation error:", error.message);
} else if (error instanceof TimeoutError) {
console.error("Timeout error:", error.message);
}
// Scripts will be empty array on error
console.log("Scripts loaded:", res.locals.serverTagScripts?.length || 0);
},
})
);
```
## Browser Compatibility
ServerTag works with all browsers supported by the generated script tags. The middleware itself runs on Node.js 16+.
# Others (HTML/JS)
Source: https://docs.ad-unblock.com/guides/html-javascript
Direct integration using vanilla HTML and JavaScript
**Where to find your verification code**: Your verification code is your
**Account ID**, shown at the top of your AdUnblock dashboard.
The `data-code` attribute is **required**. Set it to your Account ID
(verification code) — AdUnblock uses this value to verify that the script is
running on your registered domain.
Ad blockers regularly update their rules, and CDN endpoints may become blocked
over time. As a site owner, you are responsible for using the latest valid CDN
endpoints by regularly checking the System Status page or implementing
server-side fetching from `https://public.adunblocker.com/api/vendor_scripts`.
Add the following script to your website's `` section:
```html theme={null}
```
**Important:**
* Replace `YOUR_VERIFICATION_CODE` with your unique verification code from the dashboard.
* Replace `LATEST_SCRIPT_URL` with the current script URL. Fetch the latest script URL from: `https://public.adunblocker.com/api/vendor_scripts`
For production environments, implement server-side fetching from our API with proper caching.
After adding the script, verify your integration is working properly by navigating to your site and checking if the ads are visible.
## Verification Code
Your unique verification code (shown as `YOUR_VERIFICATION_CODE` in the examples above) is required for AdUnblock to verify your integration. This code is specific to your registered domain.
## Available Script Sources
We provide multiple CDN endpoints to enhance reliability. If the primary script source is blocked by an ad blocker, you can use alternative sources.
**View System Status**: Check our status page to see all available endpoints
and their current status.
You can also fetch the latest list of valid script sources programmatically from our configuration API:
```
https://public.adunblocker.com/api/vendor_scripts
```
### Important Notice
As a site owner, you are responsible for ensuring your integration uses the latest valid CDN endpoints. Ad blockers regularly update their rules, which may block our endpoints. We recommend:
* Regularly check the System Status page for updated endpoint information
* For production environments, implement server-side fetching from our API with proper caching
* Use the API endpoint `https://public.adunblocker.com/api/vendor_scripts` to programmatically retrieve the latest valid scripts
* Never implement client-side fallbacks that fetch from our API directly
## Need help with implementation?
Our support team is ready to assist you with any questions or issues.
Get personalized help from our technical support team.
# Next.js
Source: https://docs.ad-unblock.com/guides/nextjs
Script loading for Next.js applications with React Server Components
A Next.js React Server Component for fetching and rendering external JavaScript files on the server-side before page rendering. This package provides secure, cached script loading with TypeScript support.
## Installation
```bash theme={null}
npm install @adunblock/server-tag-nextjs
```
Every rendered `";
}, $scripts);
return implode("\n", $scriptTags);
})
!!}
My Page