scriptmonitoring.comdocs
Get startedVite

Install with the Vite plugin

Install @scriptmonitoring/vite and register scriptMonitoring() in vite.config.ts. Every production build gets the tag first in the head.

All plansUpdated

On a Vite project you install Script Monitoring as a build plugin: add @scriptmonitoring/vite and register scriptMonitoring() in vite.config.ts. Every production build then carries the tag at the very start of the <head>, so the install is enforced by your build rather than remembered by whoever edits index.html.

Install with Vite: add the tag to index.html so it is the first script in the head.Install with Vite: add the tag to index.html so it is the first script in the head.

How do I install the plugin?#

  1. In the dashboard, open Developers > Setup, go to step 3, Install, and pick Vite.

  2. Install the package (1. Install package):

    npm i @scriptmonitoring/vite
    

    With yarn, yarn add @scriptmonitoring/vite. With pnpm, pnpm i @scriptmonitoring/vite.

  3. Register the plugin (2. Register the plugin). This is the dashboard's snippet with your script URL filled in:

    // vite.config.ts
    import { scriptMonitoring } from '@scriptmonitoring/vite';
    import { defineConfig } from 'vite';
    
    export default defineConfig({
      plugins: [
        scriptMonitoring({ scriptUrl: 'https://<teamID>.cdn.scriptmt.com/sm.js' }), // <- Here
        // ...other plugins
      ],
    });
    
  4. Build and deploy, then check Verify it's working.

Which options does scriptMonitoring() take?#

OptionWhat it does
teamIdYour team ID. Loads https://<teamID>.cdn.scriptmt.com/sm.js. The recommended option.
scriptUrlYour full script URL, as in the dashboard snippet. Deprecated: it still works, with a build warning.
enabledTurns the plugin on or off. Defaults to off in the dev server and on in builds.

The same configuration with teamId:

// vite.config.ts
import { scriptMonitoring } from '@scriptmonitoring/vite';
import { defineConfig } from 'vite';

export default defineConfig({
  plugins: [scriptMonitoring({ teamId: '<teamID>' })],
});

Why don't I see the tag in development?#

The plugin skips the dev server unless you pass enabled: true, and logs "[Script Monitoring] Plugin is disabled (because you are in development mode)". Check the built dist/index.html instead: the first element in <head> is the Script Monitoring tag.

Frequently asked questions#

Why is the tag missing when I run the dev server?

The plugin is off in the Vite dev server by default and logs a warning saying so. It runs in production builds. Pass enabled: true to turn it on in development too.

Should I use scriptUrl or teamId?

The dashboard snippet passes scriptUrl. The package now marks scriptUrl as deprecated in favor of teamId, and prints a warning at build time when you use it. scriptMonitoring({ teamId: '<teamID>' }) loads the same script without the warning.

Where does the plugin put the tag?

At the very start of the <head> (head-prepend), with referrerpolicy="origin", in every HTML file Vite builds.

Questions? Ask in the chat, or in the dashboard.View as Markdown