Don't track in development
Keep local and staging builds out of your numbers, and test tracking on your machine.
Loomduct skips local addresses by default, so npm run dev sends nothing. You only need to act for staging sites, or to test tracking on your machine.
Before you start
- Loomduct installed on your site. See the Quick start.
Skipped by default
The SDK sends nothing on localhost, *.localhost, 127.0.0.1, [::1] and *.local.
Keep staging out
For staging or preview sites on a real domain, only start Loomduct in production:
import { loomduct } from './loomduct'
if (import.meta.env.PROD) {
loomduct.load()
}Use your framework's own production check, like process.env.NODE_ENV === 'production'.
Test tracking on your machine
Turn on allowLocalhost for a moment:
import { Loomduct } from '@loomduct/js'
import { webAnalytics } from '@loomduct/js/web-analytics'
export const loomduct = new Loomduct({
token: 'lmt_your_project_token',
plugins: [webAnalytics()],
allowLocalhost: true,
})With npm and hot reload, two instances can end up running. Stop the old one when the module reloads:
import.meta.hot?.dispose(() => loomduct.destroy())Remove it again before you deploy.
See what the SDK does
In development builds (when process.env.NODE_ENV is not production), the SDK logs every event, answer and error in the browser console, with the prefix [loomduct], and says why it skips a page. Set debug: false to turn it off, or debug: true (data-debug on the script tag) to turn it on in production.
Check that it worked
Open your staging site. The browser's network tab shows no request to /l/e.