# Install with NPM

> Run npx @scriptmonitoring/cli after your build to inject the Script Monitoring tag into every static HTML file. Works for dist and .next output and in CI.

Source: https://docs.scriptmonitoring.com/install/npm/ · Plan: All plans · Updated 2026-11-07

The NPM method runs the Script Monitoring CLI, `@scriptmonitoring/cli`, from npm. It injects the tag into your static HTML after your build: run `npx @scriptmonitoring/cli@latest --team-id <teamID>` as the last step of your build or CI job. It suits static sites and any build you would rather not change, and it keeps the tag in place without anyone editing HTML by hand.

![Setup step 3, Install: choosing NPM shows the npx command with your Team ID to run after your build, and Copy command copies it.](https://docs.scriptmonitoring.com/videos/install-npm-flow-light.webp)

## How do I run it?

1. In the dashboard, open **Developers > Setup**, go to step 3, **Install**, and pick **NPM**.
2. Copy the command. Your team ID is already in it: the number in the **Team ID** chip in the top bar, never the docs example `14827391650423`.

   ```shell
   # Run after your build step
   npm_config_yes=true npx @scriptmonitoring/cli@latest --team-id <teamID>

   # Or specify a directory
   npm_config_yes=true npx @scriptmonitoring/cli@latest --team-id <teamID> --dir ./dist
   ```

3. Add it to your build, after the step that writes your HTML. For example, in `package.json`:

   ```json
   {
     "scripts": {
       "build": "vite build && npm_config_yes=true npx @scriptmonitoring/cli@latest --team-id <teamID>"
     }
   }
   ```

4. Deploy the processed files and check [Verify it's working](https://docs.scriptmonitoring.com/verify/).

## Which options does the CLI take?

| Option | What it does |
| --- | --- |
| `--team-id`, `-t` | Required. Your team ID. Builds the CDN script URL `https://<teamID>.cdn.scriptmt.com/sm.js`. |
| `--dir`, `-d` | The folder (or single HTML file) to process. Defaults to `dist`, then `.next`. |
| `--silent`, `-s` | Stops the CLI from listing each processed file. |

Run `npx @scriptmonitoring/cli --help` for the full list.

Missing `--team-id` fails before HTML files are changed. Third-party scripts keep their original URLs; the CLI injects only your CDN script tag.

## What does it change in my HTML?

In every HTML file it finds (skipping `node_modules` and `vendor`), the CLI removes any existing Script Monitoring tag and inserts the current one before the first `<link>` or `<script>`:

```html
<script src="https://<teamID>.cdn.scriptmt.com/sm.js" referrerpolicy="origin" data-src="..."></script>
```

## Frequently asked questions

### Which folder does the CLI process?

By default it looks for `dist`, then `.next`, in the current directory. Pass `--dir` (or `-d`) to point it at another folder or a single HTML file.

### Is it safe to run twice?

Yes. Before injecting, the CLI removes any Script Monitoring tag it finds, so a second run leaves one tag, not two.

### Where in the HTML does it put the tag?

Right before the first `<link>` or `<script>` tag in each file, with `referrerpolicy="origin"`.

### What does npm_config_yes=true do?

It answers yes to npx's install prompt, so the command runs unattended in CI.

## Related

- [Install the script tag](https://docs.scriptmonitoring.com/install/)
- [HTML](https://docs.scriptmonitoring.com/install/html/)
