# Frameworks and site builders

The NOCRUMBS™ script is one tag in the `<head>` of every page. Put it once in the file that
every page shares, and use your own domain in `data-domain`. There is no package to install
and no key to set.

```html
<script defer data-domain="example.com" src="https://ncrmb.com/s.js"></script>
```

Using an AI coding assistant? [Give it the install prompt](https://nocrumbs.io/docs/ai.md) instead.

## Plain HTML

Add the tag inside `<head>` on every page. Static site generators such as Hugo, Jekyll, and
Eleventy have a base layout or a head partial that every page uses: add it there once.

## Next.js (App Router)

In `app/layout.tsx`, load the script with `next/script`:

```tsx
import Script from 'next/script';

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        {children}
        <Script data-domain="example.com" src="https://ncrmb.com/s.js" strategy="afterInteractive" />
      </body>
    </html>
  );
}
```

## Next.js (Pages Router)

In `pages/_app.tsx`:

```tsx
import type { AppProps } from 'next/app';
import Script from 'next/script';

export default function App({ Component, pageProps }: AppProps) {
  return (
    <>
      <Script data-domain="example.com" src="https://ncrmb.com/s.js" strategy="afterInteractive" />
      <Component {...pageProps} />
    </>
  );
}
```

## React, Vue, Angular, and other Vite apps

Add the tag to the `<head>` of `index.html` (`src/index.html` in Angular). Route changes are
counted on their own.

## Nuxt

In `nuxt.config.ts`:

```ts
export default defineNuxtConfig({
  app: {
    head: {
      script: [{ src: 'https://ncrmb.com/s.js', defer: true, 'data-domain': 'example.com' }],
    },
  },
});
```

## SvelteKit

Add the tag to `src/app.html`, inside `<head>` before `%sveltekit.head%`.

## Astro

Add the tag to the `<head>` of your base layout, with `is:inline` so Astro leaves it as it is:

```astro
<script is:inline defer data-domain="example.com" src="https://ncrmb.com/s.js"></script>
```

## React Router and Remix

Add the tag inside `<head>` in `app/root.tsx`:

```tsx
<script defer data-domain="example.com" src="https://ncrmb.com/s.js" />
```

## Gatsby

In `gatsby-ssr.js` (or `gatsby-ssr.tsx`):

```jsx
export const onRenderBody = ({ setHeadComponents }) => {
  setHeadComponents([
    <script key="nocrumbs" defer data-domain="example.com" src="https://ncrmb.com/s.js" />,
  ]);
};
```

## WordPress

Use a plugin that adds code to the head of every page, and paste the tag there. If you edit
your theme instead, use a child theme, so a theme update does not remove the tag.

## Site builders

Paste the tag into the field your builder offers for code in the head of every page, then
publish the site. Some builders offer this field only on paid plans.

| Builder | Where the tag goes |
| --- | --- |
| Shopify | Online Store, Themes, Edit code, `layout/theme.liquid`, just before `</head>` |
| Webflow | Site settings, Custom code, Head code |
| Squarespace | Code Injection, Header |
| Wix | Settings, Custom code, placed in the head on all pages |
| Ghost | Settings, Code injection, Site header |
| Framer | Site settings, Custom code, the start of the head |

## Content Security Policy

If your site sends a `Content-Security-Policy` header, allow the script host in two
directives, beside what they already allow:

```
script-src https://ncrmb.com
connect-src https://ncrmb.com
```

## TypeScript

To call [custom events](https://nocrumbs.io/docs/events.md) from TypeScript, declare the function once:

```ts
declare global {
  interface Window {
    nocrumbs?: (
      name: string,
      options?: { props?: Record<string, string | number | boolean> },
    ) => void;
  }
}

window.nocrumbs?.('Signup', { props: { plan: 'Starter' } });
```

## Check the install

Open your deployed site in a browser. Visits from `localhost` are not counted. The dashboard
shows "Waiting for the first pageview" and switches to your numbers within seconds of the
first visit. If nothing arrives, check that `data-domain` matches the domain you added, and
that an ad blocker is not blocking the script in your own browser.
