Add Mosaicora social images to Next.js

Use each route’s canonical URL to publish a predictable Mosaicora image in Open Graph and Twitter metadata. Optionally version the image URL when refreshed content needs a new asset after a social platform re-scrapes the page.

What this integration does

  • Builds one stable Mosaicora image URL for each public route.
  • Adds that URL to the Open Graph and Twitter metadata social crawlers read.
  • Optionally adds a deliberate v version for refreshed social images.
  • Optionally sends exact image content through typed JSON-LD.

Expected outcome

Each public route exposes one stable Mosaicora image URL in crawler-readable metadata, with optional render values when the image should use content different from the page defaults.

How the pieces connect

The integration connects content your application already knows about to the metadata a social crawler can read.

  1. Next.js route data
  2. Canonical URL and optional render values
  3. Mosaicora image URL
  4. Open Graph and Twitter tags
  5. Social preview

Use this integration when

  • Your application uses the Next.js App Router.
  • Route metadata is rendered on the server.
  • Each integrated page has a public canonical URL.

Choose another path

Choose this path when your Node.js application does not use Next.js App Router.

Use the framework-agnostic npm package

Before you begin

  • A Next.js 16 App Router project using React 19 and Node.js 20 or newer.
  • The public canonical URL for the route you want to connect.
  • Your public Mosaicora site ID. A site ID identifies the site configuration. It is not a secret API credential.
  • A route that can export static metadata or generateMetadata from a Server Component.
Package
@mosaicora/plugin-nextjs 1.0.4
Framework
Next.js 16 and React 19
Runtime
Node.js 20+
License
MIT
1

Install the Next.js package

Add the native App Router helpers to the application that publishes your metadata.

Run the installation command from the root of your Next.js project. The package includes the framework-agnostic Mosaicora core as a dependency.

Install with pnpm

pnpm add @mosaicora/plugin-nextjs

Expected result

  • The dependency appears in package.json.
  • Your package manager completes without peer dependency errors.
2

Prepare the canonical page data

Use the same absolute canonical URL for the page, metadata, and Mosaicora image path.

Resolve pageHref from trusted application data. It is the absolute public page URL and the canonical URL the page publishes. Dynamic route query parameters are preserved in deterministic order, while hash fragments are ignored.

Use one pageHref for each public page identity. Alternate routes should publish their own canonical URL before creating Mosaicora metadata.

Route values

const siteId = "321cac22d2103fb1660c50bd";
const canonicalUrl = "https://example.com/products/view";
3

Create the Open Graph metadata

Generate matching Open Graph and X/Twitter image metadata with createMosaicoraMetadata.

Spread the helper output into the metadata returned by your route. You can add the page title, description, canonical alternate, and other standard Next.js metadata alongside it.

For dynamic routes, resolve the route data inside generateMetadata and pass the final canonical URL to the helper.

Static App Router metadata

import type { Metadata } from "next";
import { createMosaicoraMetadata } from "@mosaicora/plugin-nextjs";

const canonicalUrl = "https://example.com/products/view";

export const metadata: Metadata = {
  title: "Example product",
  alternates: { canonical: canonicalUrl },
  ...createMosaicoraMetadata({
    siteId: "321cac22d2103fb1660c50bd",
    pageHref: canonicalUrl,
    alt: "Example product social preview",
  }),
};

Dynamic route metadata

export async function generateMetadata({ params }): Promise<Metadata> {
  const { slug } = await params;
  const product = await getProduct(slug);

  return {
    title: product.title,
    description: product.description,
    ...createMosaicoraMetadata({
      siteId: "321cac22d2103fb1660c50bd",
      pageHref: product.canonicalUrl,
      alt: product.title,
    }),
  };
}

Expected result

  • The rendered page contains og:image and twitter:image tags.
  • Both tags point to the same cdn.mosaicora.io image URL.
4

Version a refreshed social image

Opt in to a new v URL when updated image content needs a separately cacheable asset.

Use cacheVersion for a deliberate deployment or content revision. It accepts any non-empty developer-controlled string and is the recommended choice when you decide exactly when the image changes.

Use cacheBuster: "monthly" only when a regular rotation is suitable. If both options are present, cacheVersion takes precedence. Without either option, the existing image URL behavior is unchanged.

Manual image version

...createMosaicoraMetadata({
  siteId,
  pageHref: canonicalUrl,
  cacheVersion: "release-2026-07",
})

// Both og:image and twitter:image use:
// https://cdn.mosaicora.io/s/321cac22d2103fb1660c50bd/products/view.jpg?v=release-2026-07

Monthly image version

...createMosaicoraMetadata({
  siteId,
  pageHref: canonicalUrl,
  cacheBuster: "monthly",
})

// For July 2026, both image tags use:
// https://cdn.mosaicora.io/s/321cac22d2103fb1660c50bd/products/view.jpg?v=2026-07
5

Add JSON-LD render overrides

Tell the Mosaicora generator which exact page values to render in the image.

MosaicoraOgJsonLd preserves normal Schema.org fields and adds the typed mosaicora:og v3 block. The override is not a replacement for SEO metadata: it gives the image generator precise content such as the title, description, price, and feature list.

Place the component in the page or a route-specific server component so its values describe the same canonical page as the metadata.

Product JSON-LD override

import { MosaicoraOgJsonLd } from "@mosaicora/plugin-nextjs";

export default function ProductJsonLd() {
  return (
    <MosaicoraOgJsonLd
      schemaType="Product"
      name="Example product"
      description="A polished preview for every product page."
      url="https://example.com/products/view"
      offers={{
        "@type": "Offer",
        price: "49",
        priceCurrency: "USD",
      }}
      mosaicoraOg={{
        schemaVersion: 3,
        semanticValues: {
          "content.title": "Example product",
          "content.description": "A polished product preview.",
          "product.price": "$49",
          "product.features": ["Fast setup", "Consistent previews"],
        },
      }}
    />
  );
}
6

Verify the deployed route

Confirm the final HTML exposes the image URL and render instructions to crawlers.

Deploy or expose the route at its public canonical URL. Inspect the rendered HTML, then run that URL through the Mosaicora Open Graph Checker.

Check that the canonical URL, og:image, twitter:image, image dimensions, alt text, and mosaicora:og semantic values all describe the same page.

When using a version, confirm the published image URL ends with only the expected v value. A social platform may still retain its existing page preview until it chooses to re-scrape.

Expected result

  • The route returns a successful public response.
  • The social preview uses the expected Mosaicora URL.
  • The JSON-LD script parses and contains schemaVersion 3.

Reference

Advanced usage

Deterministic URL behavior

The helper creates stable image addresses from the page identity.

  • Retained page query entries are sorted by key and value, then percent-encoded into the CDN path before .jpg.
  • The reserved v cache token remains after .jpg; other post-.jpg query values are ignored for page lookup.
  • Hash fragments are ignored.
  • UTF-8 path segments remain readable.
  • cacheVersion replaces a source v and takes precedence over cacheBuster.
  • cacheBuster supports daily, weekly, monthly, and custom duration schedules.

Public exports

Use the high-level Next.js helpers or the re-exported core primitives.

  • getMosaicoraOgImageUrl
  • createMosaicoraMetadata
  • MosaicoraOgJsonLd
  • buildOgImageCacheBuster and OgImageCacheBuster
  • Core URL helpers, JSON-LD builders, semantic values, and role-specific types

Help

Troubleshooting

The metadata is missing from the initial HTML

Keep metadata exports in a Server Component route. Do not move metadata generation into a client component or a browser-only effect.

Different URLs generate unexpected image paths

Normalize one absolute canonical URL and reuse it for alternates, pageHref, and the JSON-LD url field.

The image renders, but uses the wrong text

Inspect the mosaicora:og semanticValues. Add explicit title, description, price, or feature overrides for the values the generator should render exactly.

A social post still shows the older image

First confirm the public page publishes the updated metadata and image. Add cacheVersion for the changed asset or use the least-frequent suitable cacheBuster schedule, then use the platform’s refresh tool if available. The platform controls whether and when it re-scrapes the page.

Need help with another publishing workflow?

Open the dashboard to start with the current integrations, or contact us if you need a different workflow.