Skip to content

Install with npm

Add the Loomduct SDK to a JavaScript or TypeScript app.

Use npm for apps built with a bundler, like Vite, Next.js, webpack, Rollup or esbuild. For a site without a build step, install with the script tag instead.

Install with your AI agent

Add Loomduct analytics to this project. Follow the steps in https://loomduct.com/docs/install/ai-agent.md Ask me for the project token. Do not read .env files.

Before you start

  • A Loomduct project and its project token. In the dashboard, open the project menu, select Project settings, then Copy project token.

Steps

Install the package

npm install @loomduct/js

Create one instance

Create a file that makes one Loomduct instance and exports it, so the rest of your app can import it. Creating the instance sends nothing.

src/loomduct.ts
import { Loomduct } from '@loomduct/js'
import { webAnalytics } from '@loomduct/js/web-analytics'

export const loomduct = new Loomduct({
  token: 'lmt_your_project_token',
  plugins: [webAnalytics()],
})

webAnalytics() tracks page views and time on page. The token is public, so it is fine in frontend code.

Call load() when the app starts

Call load() once, in the file that starts your app:

src/main.ts
import { loomduct } from './loomduct'

loomduct.load()

Tracking starts with load(). To start later, for example after consent, call load() only then. Calls you make before it are kept and sent once it runs.

Check that it worked

  1. Deploy your app and open it in a new tab. Loomduct skips localhost; to test on your machine, add allowLocalhost: true to the options for a moment.
  2. Open your project in the dashboard. Your visit shows up as online now on the Overview within a few seconds.

In development builds, the SDK logs what it does in the browser console, and why it skips localhost.