# Add the script on your own site

Plain HTML, Next.js, Astro and other sites you build yourself.

## Plain HTML or Astro

Paste the line in your shared layout, before `</head>`.

```html title="Your line"
<script async src="https://YOUR-LINK-DOMAIN/t.js" data-key="mk_YOUR_KEY"></script>
```

## Next.js

```tsx title="app/layout.tsx"
export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <head>
        <script async src="https://YOUR-LINK-DOMAIN/t.js" data-key="mk_YOUR_KEY" />
      </head>
      <body>{children}</body>
    </html>
  );
}
```

## Pick the forms to track

Add one attribute to a form. The value is its name in your reports.

```html title="A tracked form"
<form data-totems="apply" action="/apply" method="post">
  <input name="email" type="email" autocomplete="email">
  <button>Send</button>
</form>
```

The script adds the visitor id in a hidden field named `tm_v`. It reads email, phone and name only. `data-totems="off"` turns a form off.

## Tell us who sent a form

Call this after your server says the form was saved:

```js title="After a form is saved"
totems.identify({ email: 'alex@example.com', name: 'Alex' })
```

You can also send `phone` in international form, such as `+14155550123`. This is a claim, not proof. It can't replace a person who is already joined to that browser. A payment, or a call from your server, is stronger.

## Send a custom event

```js title="A custom event"
totems.track('joined_webinar')
```

Browser events are marked unverified. They can never make a sale. Send sales from your server with the [Sales API](/docs/api/reference/sales).

## Pass the id yourself

`totems.visitor()` gives the visitor id, or `null` without consent. `totems.url('https://...')` adds it to a booking or checkout address. `totems.status()` helps you check the setup.

## Content security policy

If your site uses one, allow your link domain in `script-src` and `connect-src`.

## How to know it worked

Press **Check my site** in Settings, then Script.
