DataSag guides · Updated 27 October 2026

Fix duplicate analytics pageviews on Docusaurus

Multiple tracking requests do not necessarily mean duplicate pageviews. DataSag sends pageviews, scroll milestones, engagement updates and custom events. Inspect eventName before removing code. This guide applies to Docusaurus.

Start with the Docusaurus installation

Add an object to the existing Docusaurus scripts array with src, defer and data-datasag-key attributes. Preserve the rest of your configuration. Build and serve the generated production site, then test a documentation route directly and through client navigation. The config runs in Node.js, so browser event calls do not belong there.

Docusaurus accepts string script entries, but an object is needed here to preserve the public tracking-key attribute and explicit non-blocking loading. Do not also insert the tracker through a client module, swizzled theme component or individual MDX page.

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 duplicate analytics pageviews in Docusaurus

  1. Search the config scripts array, clientModules, swizzled theme components and MDX content for DataSag installation code. A global config entry and a theme effect can both initialize the tracker in the same documentation document.
  2. Inspect custom routing listeners in client modules before removing anything. The current tracker observes History API pathname changes. A second pageview sender requires a demonstrated gap rather than an assumption that client routing needs manual tracking.
  3. Rebuild and serve production output, then test direct entry, a sidebar navigation and Back. Separate null-name pageviews from automatic scroll, engagement and named click events when comparing the resulting network sequence.

One config-level loader covers tested documentation transitions without an overlapping client-module pageview sender.

Complete the collection checks

  1. Open Network and filter /api/track. Reload once without clicking or scrolling. Inspect eventName in each payload: null identifies a pageview; scroll, click_heatmap and __datasag_engagement are other records.
  2. Count rendered script elements with data-datasag-key. There should be one intended installation for this project. Search your code, site header settings, embeds and tag manager for additional copies.
  3. Remove redundant script insertion mechanisms, keeping the site-wide installation. Two copies execute independently even when their browser download is cached.
  4. Check for custom router listeners that manually send pageviews. The current tracker handles pushState, replaceState and popstate and ignores a repeated pathname. Do not add a second pageview implementation without a demonstrated gap.
  5. Repeat a direct load, a second route and browser Back. Correlate pageview records with actual path changes. A query-only change on the same pathname is not a new pageview in the current tracker.
[...document.querySelectorAll('script[data-datasag-key]')]
  .map(script => ({
    src: script.src,
    key: script.getAttribute('data-datasag-key')
  }));

What a successful check looks like

A single installation and one pageview dispatch for each actual pathname change in the tested sequence. Additional engagement records remain available.

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

Comparing the total number of events with the number of pageviews produces a false duplicate diagnosis. Keep the event categories separate throughout the check.

Installation snippet for Docusaurus

The shared installation belongs in the scripts array in docusaurus.config.js or docusaurus.config.ts. Use this as the installation reference while checking the procedure above.

// Merge this entry into the existing scripts array.
export default {
  scripts: [{
    src: "https://www.datasag.com/tracker.js",
    defer: true,
    "data-datasag-key": "YOUR_PUBLIC_KEY"
  }]
};

Related Docusaurus guides

Full Docusaurus setup guide · Search and AI visibility

References

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