> For the complete documentation index, see [llms.txt](https://docs.akinon.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.akinon.com/technical-guides/project-zero/next.js/seo-management.md).

# SEO Management

The SEO tags in your project should be included in the following files:

* `src/app/[commerce]/[locale]/[currency]/layout.tsx`
* `src/app/[commerce]/[locale]/[currency]/(root)/category/[pk]/page.tsx`
* `src/app/[commerce]/[locale]/[currency]/(root)/list/page.tsx`
* `src/app/[commerce]/[locale]/[currency]/(root)/product/[pk]/page.tsx`
* `src/app/[commerce]/[locale]/[currency]/(root)/special-page/[pk]/page.tsx`
* `src/app/[commerce]/[locale]/[currency]/(root)/group-product/[pk]/page.tsx`

If your project has a category landing page, you also need to edit the SEO tags for the category landing page created within the root.

* `src/app/[commerce]/[locale]/[currency]/(root)/categoryLandigPage/page.tsx`

To create metadata, first import the existing Metadata in Next.js:

```
import { Metadata } from 'next';
```

An async function named **generateMetadata** is created. This function runs before the **function root** and puts metadata in head.

The `params` and `searchParams` parameters, as well as the `props` you want to display in the metadata, can be added to the **generateMetadata** function.

Examples of **generateMetadata** function with different parameter options:

**Without parameters:**

```
export async function generateMetadata() {}
```

**With parameters:**

```
export async function generateMetadata({ params, searchParams }) {}
```

**With parameters and props:**

`<{ pk: number }>` represents a single attribute to be extracted from props.

```
export async function generateMetadata({ params, searchParams }: PageProps<{ pk: number }>) {}
```

SEO data such as title, description, canonical, openGraph can also be added to **metadata**.

Example **Metadata** variable:

```
const result: Metadata = {
  title: 'title',
  description: 'description',
  keywords: 'keywords',
  viewport:
    'width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0',
  twitter: {
    title: 'title',
    description: 'description'
  },
  alternates: {
    canonical: 'canonicalUrl'
  },
  openGraph: {
    title: 'title',
    description: 'description',
    images: 'image'
  },
};
```

Example of the **generateMetadata** function for `src/app/[commerce]/[locale]/[currency]/(root)/product/[pk]/page.tsx`:

```
export async function generateMetadata({
  params,
  searchParams
}: PageProps<{ pk: number; locale: string }>) {
  const nextHeaders = pzUrl();
  const pageUrl = new URL(
    nextHeaders.get('pz-url') ?? process.env.NEXT_PUBLIC_URL
  );

  const canonicalUrl = `${process.env.NEXT_PUBLIC_URL}${pageUrl?.pathname}`;
  let result: Metadata = {};

  try {
    const {
      data: { product }
    } = await getProductData({
      pk: params.pk,
      searchParams
    });
    result = {
      title: product.name,
      description: product.attributes.description,
      twitter: {
        title: product.name,
        description: product.attributes.description
      },
      openGraph: {
        title: product.name,
        description: product.attributes.description,
        images: product.productimage_set?.map((item) => ({
          url: item.image
        }))
      },
      alternates: {
        canonical: canonicalUrl
      }
    };
    // eslint-disable-next-line no-empty
  } catch (error) {}

  return result;
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.akinon.com/technical-guides/project-zero/next.js/seo-management.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
