Add Mosaicora to any website automatically

Add one hosted script to your site and let Mosaicora publish matching Open Graph and Twitter image tags from each page's canonical URL. It is the quickest setup when you can edit the document head.

What this integration does

  • Adds Mosaicora image tags without a framework package or build integration.
  • Uses the page's canonical URL, with the current browser URL as a safe fallback.
  • Keeps every query parameter and sorts them into a predictable image URL.

Expected outcome

Each browser page receives a stable Mosaicora image URL based on its canonical address, with the full query string preserved and sorted for predictable results.

How the pieces connect

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

  1. Public page URL
  2. Automatic browser script
  3. Mosaicora image URL
  4. Open Graph and Twitter tags
  5. Social preview

Use this integration when

  • You can add a script tag to the document head or a site-wide code area.
  • You want the quickest Mosaicora setup across an existing website.
  • Your target preview service executes browser JavaScript, or you can use a server-rendered integration when it does not.

Choose another path

Choose a server-rendered integration when social crawlers must receive image tags in the initial HTML response.

Use the Next.js integration

Before you begin

  • Access to your website's document head or site-wide custom code area.
  • Your public Mosaicora site ID from the site overview.
  • A public page URL that can load the hosted Mosaicora script.
Setup
One script tag
Compatibility
Any website with head access
Runtime
Modern browsers
Site ID
Public, not a secret
1

Copy your Mosaicora site ID

Use the public identifier for the site configuration that should create the images.

Open the site overview in Mosaicora and copy the site ID. This value identifies your public image configuration and is safe to include in website markup.

Example site ID

321cac22d2103fb1660c50bd

Expected result

  • The site ID matches the site you want to connect.
2

Add the automatic script

Load the hosted helper and initialize it with one data attribute.

Add the script to the document head or your platform's site-wide custom code area. The data-og-site-id attribute starts the integration automatically when the script loads.

Add the snippet once. Repeated initialization is safe, but one site-wide script keeps the setup easier to maintain.

Automatic setup

<script
  src="https://static.mosaicora.io/js/og-image.min.js"
  data-og-site-id="321cac22d2103fb1660c50bd"
></script>

Expected result

  • The script loads successfully from static.mosaicora.io.
  • The data-og-site-id attribute contains your site ID.
3

Confirm the page identity

Let the helper use the canonical URL, or fall back to the current browser address.

The helper reads a valid link rel="canonical" value first. When the canonical link is missing or invalid, it uses window.location.href.

Every query parameter is retained and sorted by key and value. Hash fragments are ignored, duplicate slashes are normalized, and the .jpg suffix appears before the query string.

Optional canonical URL

<link
  rel="canonical"
  href="https://example.com/products/view?sku=123&campaign=launch"
/>

Generated image URL

https://cdn.mosaicora.io/s/321cac22d2103fb1660c50bd/products/view.jpg?campaign=launch&sku=123
4

Use manual initialization when needed

Load the helper once and start it from your own browser code.

Automatic initialization is the recommended setup. If your tag manager or application controls script timing, omit the data attribute and call the public initializer after the helper loads.

Manual setup

<script src="https://static.mosaicora.io/js/og-image.min.js"></script>
<script>
  window.MosaicoraOgImage.init({
    siteId: "321cac22d2103fb1660c50bd",
  });
</script>

Expected result

  • The initializer receives only the siteId option.
  • The call runs after the hosted helper has loaded.
5

Verify the browser and crawler output

Confirm the injected tags, then check whether your target crawler can read them.

Open a public page, inspect the live browser DOM, and confirm that og:image and twitter:image point to the expected cdn.mosaicora.io URL.

Then inspect the initial page source or use the Open Graph Checker. Many social crawlers do not execute client-side JavaScript, so browser-injected tags may not appear to those services.

Expected result

  • The live DOM contains the expected Mosaicora image tags.
  • The image URL uses the canonical path and sorted query string.
  • Your target preview service can read the tags, or you have selected a server-rendered integration.

Reference

Advanced usage

Runtime behavior

The hosted helper keeps page-to-image mapping stable and repeatable.

  • A valid canonical URL takes precedence over window.location.href.
  • Every query parameter is preserved and sorted by key and value.
  • The .jpg suffix appears before the query string.
  • Re-initialization replaces only Mosaicora-owned tags.

Crawler compatibility

Choose the metadata delivery method that matches the services sharing your pages.

  • Browser DOM inspection confirms the automatic script is running.
  • Initial page source shows what non-JavaScript crawlers receive.
  • Next.js metadata is the preferred server-rendered path for App Router sites.
  • The npm package supports other server-rendered or statically generated Node.js sites.

Help

Troubleshooting

No Mosaicora tags appear in the browser

Confirm the script request succeeds, data-og-site-id contains a valid site ID, and the snippet is placed in executable page markup rather than a field that escapes HTML.

The generated image uses the wrong page path

Inspect the page's canonical link. Remove or correct an outdated canonical URL so the helper can use the intended public page identity.

The browser shows tags but a social preview does not

The service may not execute JavaScript. Use the Next.js integration or framework-agnostic npm package so the image tags are present in the initial HTML.

Need help with another publishing workflow?

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