Skip to main content
The Pages Router adapter covers product pages and the sitemap. (Collection and site-level helpers are currently App Router only — use the core fetch helpers if you need them here.) Import from @agentshop/seo/next/pages.

Product pages

Fetch the bundle in getServerSideProps, render it with <ProductHead>:
pages/products/[handle].tsx
  • getProductSeoProps(ctx, config?) reads ctx.params.handle and returns { props: { seo: SeoBundle | null } }. Merge it into your own props if you already have a getServerSideProps.
  • <ProductHead seo /> renders everything into next/head: title, description, canonical, Open Graph (including og:type=product — unlike the App Router, raw meta tags accept it), Twitter tags, and the escaped JSON-LD script. With seo={null} it renders nothing.

Sitemap

pages/sitemap.xml.ts
Wire it as an API route instead if you prefer:
pages/api/sitemap.xml.ts
The handler sets Content-Type: application/xml; charset=utf-8 and Cache-Control: public, max-age=3600, stale-while-revalidate=86400, and responds 200 with the XML or 502 with an empty body when unavailable.

Configuration

Both helpers accept an optional SeoClientConfig as their last argument; environment variables AGENTSHOP_API_KEY and AGENTSHOP_SEO_URL fill anything you don’t pass. AGENTSHOP_API_KEY is a secret — both helpers run server-side (getServerSideProps / an API route), so keep it in a server-side env var, never a NEXT_PUBLIC_* one. All helpers follow the never-throw contract.