DataSag guides · Updated 27 October 2026

Fix DataSag analytics not working on Express with EJS

Find the first missing step in the delivery chain: published HTML, executing tracker, tracking request, successful response and project report. Changing several settings at once makes the failure harder to identify. This guide applies to Express with EJS.

Start with the Express with EJS installation

Add the deferred tracker to the shared EJS partial that emits your document head. Include that partial through the existing local include pattern in each intended template. EJS has no built-in universal layout convention, so identify your actual application composition rather than assuming a views/layout.ejs file exists.

A res.send response or a separately rendered error template can bypass your usual partials. Keep the snippet in browser HTML rather than Express middleware that only logs requests. Never include a template path supplied directly by an untrusted visitor.

Use the public project key from the DataSag project you are inspecting. A test on a preview domain does not confirm that the production domain has the same code or settings.

Fix DataSag analytics not working in Express with EJS

  1. Identify whether the affected Express handler uses res.render, res.send, a redirect or JSON. Only an HTML document that includes the tracker can execute it in the visitor browser.
  2. Inspect the actual EJS include chain and published markup. If the head partial is escaped into text, use the established trusted-local include pattern rather than disabling escaping for visitor-controlled content.
  3. If the real script loads, inspect its public key and request response. For missing actions, locate the browser fetch or form success handler. Logging an Express request on the Node server does not call window.datasag.

The failure is traced to response type, trusted template composition, or browser delivery rather than server request logging.

Complete the collection checks

  1. Confirm the change reached the public domain. Inspect the live HTML and clear only caches that serve the old document. A saved editor change may still need publishing.
  2. Check that tracker.js exists in the Network panel and that the script contains the public key from the same DataSag project you are viewing.
  3. Check whether your test browser is excluded with datasag_ignore. Restore inclusion with ?datasag_ignore=false only if this browser should count. Respect any consent controls configured on your site.
  4. Inspect the browser Console for Content Security Policy or script errors. Check /api/track request responses: 400 indicates invalid input, 404 can indicate an unknown project key, and a server failure needs investigation rather than repeated snippet changes.
  5. Try a controlled browser profile to identify an extension block. Do not bypass a visitor's privacy preferences. Then check the project's selected date range, path and domain.
  6. Collect the affected public URL, approximate time, request status and installation location for support. Omit account credentials and visitor data from screenshots.
typeof window.datasag?.track
// If undefined, first investigate whether the script executed.

new URL(location.href).searchParams.get('datasag_ignore')
// Also check for a previously saved browser exclusion.

What a successful check looks like

The first failed boundary is identified and corrected, and a new controlled visit reaches the right project. The browser Console and Network panel provide the evidence.

Record the public path you tested, the browser state, the approximate time and the observed request. Check one direct page load and one later navigation so the result covers more than the homepage.

Common mistake

Do not replace the public project key with a Supabase, Stripe or provider secret. The browser snippet uses only the project's public tracking key.

Installation snippet for Express with EJS

The shared installation belongs in a shared EJS head partial included by the intended page templates. Use this as the installation reference while checking the procedure above.

<script defer src="https://www.datasag.com/tracker.js" data-datasag-key="YOUR_PUBLIC_KEY"></script>

Related Express with EJS guides

Full Express with EJS setup guide · Search and AI visibility

References

Official Express with EJS documentation covers the integration point. For DataSag data handling, read the privacy policy. Use support if a request fails after these checks.