DataSag guides · Updated 27 October 2026

Fix duplicate analytics pageviews on Material for MkDocs

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 Material for MkDocs.

Start with the Material for MkDocs installation

Configure a local theme custom_dir and extend base.html in overrides/main.html. Add the deferred tracker inside an extrahead block while preserving parent content with super(). Merge these changes into your existing MkDocs configuration, build the site and inspect the generated document. Do not edit the installed theme package.

Material may use instant navigation, which changes the reading experience without a complete document reload. Install the global tracker once and test actual path changes. A replacement block that omits parent content can remove unrelated theme functionality.

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 Material for MkDocs

  1. Search the main.html override, custom partials, extra_javascript entries and page HTML for DataSag loaders. A theme override and a helper script that dynamically injects the tracker can both execute in the same documentation document.
  2. Inspect custom code subscribed to the theme's navigation lifecycle. It may correctly initialize page widgets but should not reinstall a global tracker on every instant-navigation update. Keep widget lifecycle work separate from analytics loader ownership.
  3. Rebuild and test direct entry, a document link and browser Back. Count actual null-name pageview payloads separately from scroll, engagement and search-related custom actions so repeated reading activity does not produce a false duplicate diagnosis.

The override installs the tracker once while page-widget lifecycle code remains separate from global analytics initialization.

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 Material for MkDocs

The shared installation belongs in an extrahead block in a theme override. Use this as the installation reference while checking the procedure above.

# Merge into mkdocs.yml:
theme:
  name: material
  custom_dir: overrides

<!-- overrides/main.html -->
{% extends "base.html" %}
{% block extrahead %}
  {{ super() }}
  <script defer src="https://www.datasag.com/tracker.js" data-datasag-key="YOUR_PUBLIC_KEY"></script>
{% endblock %}

Related Material for MkDocs guides

Full Material for MkDocs setup guide · Search and AI visibility

References

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