Skip to content
whovisited.

Analytics operations · Next.js

Keep employee QA visits out of production conversion reports

Separate staff testing from customer analytics with trusted account state, and learn what browser analytics cannot reliably exclude.

Your own tests can look like customer interest

A founder checks the pricing page, a developer tests signup, and support opens a thank-you route to reproduce a report. Those visits are real browser activity, but they are not customer demand. If staff tests reach the same success page or send the same conversion event as customers, they can add goal sessions and make a small report harder to read.

The cleanest fix is to decide whether to load the tracker before the first event is sent. For authenticated internal areas, use the application's trusted server-side session or role to omit analytics for employees. Do not base the decision only on a query parameter, a value in localStorage, or a client-side flag that anyone can edit.

Do not expect an IP exclusion switch

WhoVisited's current website settings let you configure the site's allowed origins and tracker, but they do not provide an internal-traffic or IP-exclusion filter. The ingestion path checks that the site is enabled and the request origin is allowed; an allowed origin does not tell the product whether the visitor is an employee or a customer.

An IP list is also a poor identity rule for a distributed team. Home networks change, VPN egress can be shared, and a corporate address may be used by both staff and customers. More fundamentally, a browser analytics record is not an authenticated person record. If the application already knows that an account belongs to your team, use that first-party server-side fact instead of trying to infer it from network location.

Gate tracking using a verified account role

In a Next.js App Router application, pages and layouts are Server Components by default. Resolve the signed-in account with your existing server-side session check, then render the tracker only for the audience you intend to measure. The `getVerifiedSession` and `WhoVisitedScript` names below are placeholders for your app's own session and script component; do not copy them as built-in Next.js APIs.

tsx
// In a server-rendered page or component near the authenticated route.
const session = await getVerifiedSession();
const isInternal = session?.user?.analyticsAudience === "internal";

return (
  <>
    {!isInternal && <WhoVisitedScript />}
    <main>{children}</main>
  </>
);

Use a role or organization membership that your server has verified. A user-editable profile field is not a trustworthy exclusion rule. Keep this decision close to the page or component that has current authorization data; Next.js layouts are reused during client-side navigation and do not rerender on every route change.

If an employee logs in after the tracker has already loaded on a public page, simply omitting the script on the next render does not unload the existing tracker. Its current instance continues listening for page navigation. Decide how your app handles that transition: refresh the document after the server confirms the role, or explicitly stop the already-loaded instance. `window.whovisited.stop()` clears its queue and prevents further tracking for the rest of that page lifetime; it is terminal until a fresh page load. Events already sent before the role was known cannot be recalled from the report.

Test the exclusion without hiding customer activity

  1. Start with a fresh browser profile and a public page. As a non-employee, confirm the tracker loads and the page-view request is accepted under the expected site.
  2. Sign in to a test employee account using the real authentication flow. On an internal page, verify in DevTools Network that the tracker does not send another event after the server knows the account role.
  3. If your app supports login without a full document reload, test that exact transition. A tracker loaded before login may keep running unless your application explicitly handles the change.
  4. Sign out and confirm that the application refreshes or reinitializes the public tracking path as designed. Verify the customer flow separately so an internal-only rule does not suppress ordinary visitors.
  5. Repeat with consent required and with your normal browser privacy settings. Suppression by account role must not override a visitor's consent choice or a browser privacy signal.

If employees visit public pages before signing in, the application may have no reliable signal that distinguishes them from anonymous customers. Do not claim those visits are excluded unless your site has a trustworthy way to identify them before the tracker initializes. For testing a public campaign page, use an isolated preview or a clearly documented test procedure and keep the resulting test sessions out of business decisions.

Limits and references

This approach excludes known authenticated staff requests; it cannot reliably identify anonymous employee visits to public pages or erase events already sent. It also does not make analytics an access-control mechanism. WhoVisited conversion goals count matching browser sessions, so keep your product database as the source of truth for actual signups, orders, and revenue.

Next.js documents server and client components, authentication checks, and the fact that layouts persist across client navigation. For deployment testing, see the WhoVisited guide to keeping preview deployments out of production analytics.

References and further reading

  1. Next.js: Server and Client Components
  2. Next.js: Authentication
  3. Next.js: Layout file convention
  4. WhoVisited: Keep Next.js preview deployments out of production analytics