DataSag guides · Updated 27 October 2026

Fix duplicate analytics pageviews on Grav 1.7 Twig themes

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 Grav 1.7 Twig themes.

Start with the Grav 1.7 Twig themes installation

These instructions target Grav's documented 1.7 Twig theme structure. Find the active theme's templates/partials/base.html.twig and add the deferred tracker inside head. Preserve existing blocks, asset output and page content. Maintain the change in a custom or inherited theme rather than an unmanaged installed-theme edit, then clear relevant caches and inspect public output.

Grav page templates commonly extend the shared base, but modular pages and custom templates can use another structure. Check the active theme and inheritance before assuming the base file covers every route. Do not treat a browser tracker as a Grav backend plugin.

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 Grav 1.7 Twig themes

  1. Search the active base partial, child Twig templates, modular templates and plugin-added assets for DataSag. A child block that includes parent output and adds another script can duplicate an otherwise correct base installation.
  2. Choose one global installation owner within your maintained theme or supported asset integration. Remove only the confirmed duplicate element; do not remove a parent block or asset output used by unrelated theme functionality.
  3. Clear the relevant cache and inspect the rendered HTML before testing pageview requests. Repeat on a normal page and a modular page. Separate named clicks and engagement updates from multiple null-name pageview dispatches.

The rendered Twig documents contain one tracker without removing unrelated parent blocks or theme assets.

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 Grav 1.7 Twig themes

The shared installation belongs in the head in the active theme templates/partials/base.html.twig. 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 Grav 1.7 Twig themes guides

Full Grav 1.7 Twig themes setup guide · Search and AI visibility

References

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