Documentation menuGet started: Localhost tracking

Get started

Localhost tracking in Loogika

The Loogika script runs on any address, including localhost. That makes testing easy, and it also means development visits can end up in your production numbers. This page shows three ways to keep them apart.

Last updated .

Does Loogika track localhost?

Yes. The script is not tied to the domain you registered. It records events from any origin as long as the tag has a valid site ID.

To test locally, use the same tag as in production. Requests to /api/track in the Network tab confirm that events are sent.

How do you keep development visits out of your data?

MethodHow it worksGood for
A separate development siteAdd a second site in Loogika and use its ID while you developTeams that want to test tracking before a release
Load the script in production onlyAdd the tag only when the build runs in productionProjects that do not need analytics locally
Filter your own trafficKeep the tag everywhere and exclude your visits in Site SettingsSmall sites with one or two developers

How do you use a separate site ID in development?

Store both IDs as environment variables and pick one at build time:

const siteId =
  process.env.NODE_ENV === "development"
    ? process.env.LOOGIKA_DEV_SITE_ID
    : process.env.LOOGIKA_SITE_ID;

The variable names are examples. Use the names your framework expects for values that are exposed to the browser.

How do you load the script in production only?

if (process.env.NODE_ENV === "production") {
  const s = document.createElement("script");
  s.src = "https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID";
  s.defer = true;
  document.head.appendChild(s);
}

Why does a local test show no data?

  • The site ID in the tag belongs to another site than the one you have open in the dashboard.
  • An ad blocker or a privacy extension stops the script. They work on localhost too.
  • An exclusion rule for IP address, hostname or path removes the visit.
  • You test with Puppeteer, Playwright or Selenium. Loogika classifies automated browsers as bots, so use a normal browser.