google-publisher-tag
Version:
Type-safe React wrapper for Google Publisher Tag (GPT).
72 lines (49 loc) • 1.27 kB
Markdown
Type-safe React wrapper for **Google Publisher Tag (GPT)**.
Works on any React project (Next.js, Vite, CRA, Remix).
---
## Installation
```sh
npm install google-publisher-tag
# ou
pnpm add google-publisher-tag
```
## Basic usage
```tsx
"use client";
import { GPTProvider, AdSlot } from "google-publisher-tag";
const config = {
enableSingleRequest: true,
lazyLoad: true,
};
export default function Page() {
return (
<GPTProvider config={config}>
<h1>My Page</h1>
<AdSlot
id="div-gpt-top"
adUnitPath="/1234567/home_top"
sizes={[
[],
[],
]}
targeting={{ pos: "top" }}
style={{ minHeight: 90 }}
/>
</GPTProvider>
);
}
```
<GPTProvider />
config: configurações globais (SRA, lazy load, targeting, etc).
<AdSlot />
Props principais:
id: string → id do container <div>.
adUnitPath: string → caminho do ad unit (/1234567/home_top).
sizes: googletag.GeneralSize → tamanhos suportados.
sizeMapping? → mapeamento responsivo.
targeting? → targeting específico do slot.
Hooks
useGlobalTargeting() → define targeting global.
useRefresh() → faz refresh de todos os slots ou de ids específicos.