# Installing the BestPortfolio badge

Instructions for AI assistants and coding agents (Claude, ChatGPT, Codex, Cursor, Copilot, Gemini and others) that have been asked to add the BestPortfolio "Verified" badge to someone's website. People can follow them too. The guide with pictures is at https://bestportfolio.in/badges.

## What it is

One script. It shows "Verified by BestPortfolio" with the designer's badges on their own website and links back to their page on BestPortfolio. The designer chooses how it looks (corner or inline strip, light or dark, which badges) in their BestPortfolio dashboard, so the code never needs to change after it is added.

```html
<script async src="https://bestportfolio.in/badge.js" data-portfolio="SLUG"></script>
```

`SLUG` is the designer's portfolio slug. They will give it to you, or the whole line. Never invent one.

## The rules

1. **Add it once**, in the file every page shares, as late in the body as possible. Adding it twice does no harm (only one badge shows), but once is correct.
2. **Do not add `data-position` or `data-theme`.** Those attributes override what the designer chooses in their dashboard, and their later changes there will appear to do nothing. Add them only if the designer explicitly asks to fix the look in code.
3. **Do not write code to re-inject the script** on route changes, in a `useEffect`, or inside a component that mounts on every page. The script keeps the badge in place when the site changes pages without reloading.
4. **Do not copy the script into the project** or bundle it. Load it from `https://bestportfolio.in/badge.js` so it stays current.
5. **Do not style or wrap the badge.** It draws itself inside a closed shadow root and is not affected by the site's CSS.
6. **Inline strip only:** if the designer wants the badge as a strip inside the page (for example in the footer) instead of floating in a corner, put one empty element where it should appear. The script finds it, also after a page change. Without it, an inline strip goes at the end of the page. With a floating placement the element stays empty, which is fine.

   ```html
   <div data-bestportfolio-badge></div>
   ```

   In JSX: `<div data-bestportfolio-badge="" />`

## Where it goes

### Plain HTML

Just before `</body>` in the template every page shares.

### Next.js, App Router: `app/layout.tsx`

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

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        {children}
        <Script src="https://bestportfolio.in/badge.js" data-portfolio="SLUG" strategy="afterInteractive" />
      </body>
    </html>
  );
}
```

### Next.js, Pages Router: `pages/_app.js`

```jsx
import Script from "next/script";

export default function App({ Component, pageProps }) {
  return (
    <>
      <Component {...pageProps} />
      <Script src="https://bestportfolio.in/badge.js" data-portfolio="SLUG" strategy="afterInteractive" />
    </>
  );
}
```

### React (Vite or Create React App), Vue (Vite), Angular

The plain line just before `</body>` in `index.html` (Vite: project root; Create React App: `public/index.html`; Angular: `src/index.html`).

### Nuxt: `nuxt.config.ts`

```ts
export default defineNuxtConfig({
  app: {
    head: {
      script: [
        { src: "https://bestportfolio.in/badge.js", async: true, "data-portfolio": "SLUG", tagPosition: "bodyClose" },
      ],
    },
  },
});
```

### SvelteKit: `src/app.html`

The plain line just before `</body>`.

### Astro: the layout every page shares

```astro
<script is:inline async src="https://bestportfolio.in/badge.js" data-portfolio="SLUG"></script>
```

### Website builders

Framer, Webflow, Wix, WordPress and Squarespace each have a custom code setting for the end of the body or the footer. The steps for each are at https://bestportfolio.in/badges#install.

## What to expect

- **It shows only on the address registered with the portfolio**, with or without `www`, over http or https. On `localhost`, preview and staging addresses, and any other domain, it shows nothing. That is how the badge stays trustworthy. Do not try to work around it, and do not report it as a bug.
- When it does not show, the browser console has one line starting with `BestPortfolio badge is not shown:` that says why (wrong website, portfolio not approved, or unknown slug).
- If the console says `data-position and data-theme on the script tag win over the look chosen in your Badges tab`, remove those attributes.
- To verify the install, deploy to the registered address and open it, or ask the designer to press "Check my site" in their Badges tab.

## Things that can block it

- **Content Security Policy.** Allow `https://bestportfolio.in` in `script-src`, `connect-src` and `img-src`. The badge adds its own `<style>` inside its shadow root, so `style-src` must allow inline styles.
- **Consent managers and script blockers** that hold back third-party scripts. The badge sets no cookies and stores nothing in the visitor's browser, so it can be placed in the "necessary" or "functional" group.
- **Service workers** that cache requests to other sites for a long time. The badge's data should be fetched fresh.

## What the script does

It makes two requests to bestportfolio.in: one for the badges and one that counts the visit, once per person per day, without cookies and without storing the visitor's IP address. It adds one element (`<bestportfolio-badge>`) and one global (`window.__bpBadge`). It does not read or change anything else on the page.
