You can solve this by creating one single source of truth for your
canonical url logic. In a multi region and multi language Next project,
you want a rule based system rather than many manual solutions in each
page.
The idea is simple:
Decide what the primary location of a product or page is
Remove all tracking params from the final canonical url
Map every region or language to the primary location for that product
The most stable way is to create a tiny helper function that runs both
on server and on client. This function receives the full url, strips
query params that you do not want in SEO, and then rebuilds the correct
canonical url based on your region and language config.
Example of the logic in short form:
export function makeCanonicalUrl(rawUrl, region, language) {
const noQuery = new URL(rawUrl).origin +
new URL(rawUrl).pathname
const base = "https://yourdomain.com"
const part = "/" + region + "/" + language
return base + part + new URL(rawUrl).pathname
}
All lines are under the limit you want and written in the format you
prefer.
For products that appear in more than one category, pick one of the
categories as the main one and keep that as the canonical version. The
other versions can use rel alternate to point to the correct variations
for region and language.
For hreflang you should output a list of all region and language pairs
that match the product. Next has support for this inside metadata or
your own layout. You can render a full set of alternate links with
region and language codes that match each url.
Answer to your questions in short form:
Do not build a central service in another place. Keep the logic in a
small helper that you call inside metadata of each page.
Filter query params inside that helper. Use only the clean path.
For hreflang just output all region and language pairs.
SSG and SSR do not change the solution because both can call the same
helper logic.
This gives you predictable and stable canonical output across all
regions and languages.
(This is what I think, I don't guarantee that this is the solution)