google-publisher-tag
v0.1.0
Published
Type-safe React wrapper for Google Publisher Tag (GPT).
Maintainers
Readme
google-publisher-tag
Type-safe React wrapper for Google Publisher Tag (GPT).
Works on any React project (Next.js, Vite, CRA, Remix).
Installation
npm install google-publisher-tag
# ou
pnpm add google-publisher-tagBasic usage
"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={[
[728, 90],
[320, 100],
]}
targeting={{ pos: "top" }}
style={{ minHeight: 90 }}
/>
</GPTProvider>
);
}API
config: configurações globais (SRA, lazy load, targeting, etc).
Props principais:
id: string → id do container .
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.
