Next.js Pages Router

Integration guide for Next.js applications using Pages Router

Installation

Target file: pages/_document.tsx

Quick Integration

Add the following script tag to your HTML. Replace the data-key value with your actual API key.

Script Tag
<script
          src="https://cdn.antiblocker.io/ab.js"
          data-style="minimal"
          data-key="abk_****"
        /></script>

Complete Example

Here's a complete example showing where to place the script in your pages/_document.tsx file:

pages/_document.tsx
import { Html, Head, Main, NextScript } from 'next/document'

export default function Document() {
  return (
    <Html lang="en">
      <Head />
      <body>
        <Main />
        <NextScript />
        <script
          src="https://cdn.antiblocker.io/ab.js"
          data-style="minimal"
          data-key="abk_****"
        />
      </body>
    </Html>
  )
}

Configuration

Script Attributes

data-keyYour unique AntiBlocker API key (required)
data-styleDisplay style - choose one of 6 variants: "classic", "dark", "educational", "friendly", "minimal", or "urgent"

Implementation Notes

  • Add the script in the custom _document.tsx file
  • Place it after the <NextScript /> component
  • Create pages/_document.tsx if it doesn't exist in your project
  • The script tag will be included on all pages automatically

Best Practices

Performance

Place script before closing </body> tag. The script loads asynchronously and doesn't block page rendering.

Testing

Test integration in staging environment before deploying to production. Verify script loads correctly.

API Key

Obtain your unique API key from the AntiBlocker dashboard. Never share your key publicly.

Monitoring

Track detection rates and user responses through the AntiBlocker analytics dashboard.